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/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(&ltpGainHist[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(&ltpGainHist[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;
+}