am 230ef987: am 0e89d916: Merge "DOC CHANGE: Change GTV info on intro page" into honeycomb-mr2

* commit '230ef98728f3b59a81f55dab5129aa50d5f27969':
  DOC CHANGE: Change GTV info on intro page
diff --git a/api/current.xml b/api/current.xml
index 8a924ab..bcfed90 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -94322,6 +94322,17 @@
  visibility="public"
 >
 </field>
+<field name="TYPE_RELATIVE_HUMIDITY"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="12"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TYPE_ROTATION_VECTOR"
  type="int"
  transient="false"
@@ -227976,6 +227987,17 @@
  visibility="public"
 >
 </method>
+<method name="getScaledLargeTouchSlop"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getScaledMaximumDrawingCacheSize"
  return="int"
  abstract="false"
diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java
index 894e196..93983a6 100644
--- a/core/java/android/accounts/AccountManagerService.java
+++ b/core/java/android/accounts/AccountManagerService.java
@@ -1786,22 +1786,6 @@
         }
     }
 
-    private String getMetaValue(String key) {
-        synchronized (mCacheLock) {
-            final SQLiteDatabase db = mOpenHelper.getReadableDatabase();
-            Cursor c = db.query(TABLE_META,
-                    new String[]{META_VALUE}, META_KEY + "=?", new String[]{key}, null, null, null);
-            try {
-                if (c.moveToNext()) {
-                    return c.getString(0);
-                }
-                return null;
-            } finally {
-                c.close();
-            }
-        }
-    }
-
     public IBinder onBind(Intent intent) {
         return asBinder();
     }
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 087753b..82186dd 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -931,7 +931,7 @@
 
         // associate search with owner activity
         final ComponentName appName = getAssociatedActivity();
-        if (appName != null) {
+        if (appName != null && searchManager.getSearchableInfo(appName) != null) {
             searchManager.startSearch(null, false, appName, null, false);
             dismiss();
             return true;
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index e1c9044..88e00b3 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -873,10 +873,10 @@
 
     /**
      * Create a listening, insecure RFCOMM Bluetooth socket with Service Record.
-     * <p>The link key will be unauthenticated i.e the communication is
+     * <p>The link key is not required to be authenticated, i.e the communication may be
      * vulnerable to Man In the Middle attacks. For Bluetooth 2.1 devices,
-     * the link key will be encrypted, as encryption is mandartory.
-     * For legacy devices (pre Bluetooth 2.1 devices) the link key will not
+     * the link will be encrypted, as encryption is mandartory.
+     * For legacy devices (pre Bluetooth 2.1 devices) the link will not
      * be encrypted. Use {@link #listenUsingRfcommWithServiceRecord}, if an
      * encrypted and authenticated communication channel is desired.
      * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
@@ -902,6 +902,44 @@
         return createNewRfcommSocketAndRecord(name, uuid, false, false);
     }
 
+     /**
+     * Create a listening, encrypted,
+     * RFCOMM Bluetooth socket with Service Record.
+     * <p>The link will be encrypted, but the link key is not required to be authenticated
+     * i.e the communication is vulnerable to Man In the Middle attacks. Use
+     * {@link #listenUsingRfcommWithServiceRecord}, to ensure an authenticated link key.
+     * <p> Use this socket if authentication of link key is not possible.
+     * For example, for Bluetooth 2.1 devices, if any of the devices does not have
+     * an input and output capability or just has the ability to display a numeric key,
+     * a secure socket connection is not possible and this socket can be used.
+     * Use {@link #listenUsingInsecureRfcommWithServiceRecord}, if encryption is not required.
+     * For Bluetooth 2.1 devices, the link will be encrypted, as encryption is mandartory.
+     * For more details, refer to the Security Model section 5.2 (vol 3) of
+     * Bluetooth Core Specification version 2.1 + EDR.
+     * <p>Use {@link BluetoothServerSocket#accept} to retrieve incoming
+     * connections from a listening {@link BluetoothServerSocket}.
+     * <p>The system will assign an unused RFCOMM channel to listen on.
+     * <p>The system will also register a Service Discovery
+     * Protocol (SDP) record with the local SDP server containing the specified
+     * UUID, service name, and auto-assigned channel. Remote Bluetooth devices
+     * can use the same UUID to query our SDP server and discover which channel
+     * to connect to. This SDP record will be removed when this socket is
+     * closed, or if this application closes unexpectedly.
+     * <p>Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
+     * connect to this socket from another device using the same {@link UUID}.
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
+     * @param name service name for SDP record
+     * @param uuid uuid for SDP record
+     * @return a listening RFCOMM BluetoothServerSocket
+     * @throws IOException on error, for example Bluetooth not available, or
+     *                     insufficient permissions, or channel in use.
+     * @hide
+     */
+    public BluetoothServerSocket listenUsingEncryptedRfcommWithServiceRecord(
+            String name, UUID uuid) throws IOException {
+        return createNewRfcommSocketAndRecord(name, uuid, false, true);
+    }
+
     private BluetoothServerSocket createNewRfcommSocketAndRecord(String name, UUID uuid,
             boolean auth, boolean encrypt) throws IOException {
         RfcommChannelPicker picker = new RfcommChannelPicker(uuid);
@@ -973,6 +1011,28 @@
         return socket;
     }
 
+     /**
+     * Construct an encrypted, RFCOMM server socket.
+     * Call #accept to retrieve connections to this socket.
+     * @return An RFCOMM BluetoothServerSocket
+     * @throws IOException On error, for example Bluetooth not available, or
+     *                     insufficient permissions.
+     * @hide
+     */
+    public BluetoothServerSocket listenUsingEncryptedRfcommOn(int port)
+            throws IOException {
+        BluetoothServerSocket socket = new BluetoothServerSocket(
+                BluetoothSocket.TYPE_RFCOMM, false, true, port);
+        int errno = socket.mSocket.bindListen();
+        if (errno != 0) {
+            try {
+                socket.close();
+            } catch (IOException e) {}
+            socket.mSocket.throwErrnoNative(errno);
+        }
+        return socket;
+    }
+
     /**
      * Construct a SCO server socket.
      * Call #accept to retrieve connections to this socket.
diff --git a/core/java/android/bluetooth/BluetoothDeviceProfileState.java b/core/java/android/bluetooth/BluetoothDeviceProfileState.java
index 6f3a2e7..56f236d 100644
--- a/core/java/android/bluetooth/BluetoothDeviceProfileState.java
+++ b/core/java/android/bluetooth/BluetoothDeviceProfileState.java
@@ -679,7 +679,6 @@
         @Override
         public boolean processMessage(Message message) {
             log("IncomingA2dp State->Processing Message: " + message.what);
-            Message deferMsg = new Message();
             switch(message.what) {
                 case CONNECT_HFP_OUTGOING:
                     deferMessage(message);
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index 72fca0a..dbb4271 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -235,6 +235,7 @@
             StringBlock[] blocks = mStringBlocks;
             if (blocks == null) {
                 ensureStringBlocks();
+                blocks = mStringBlocks;
             }
             outValue.string = blocks[block].get(outValue.data);
             return true;
diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java
index f2b907b..595c7d1 100644
--- a/core/java/android/hardware/Sensor.java
+++ b/core/java/android/hardware/Sensor.java
@@ -97,6 +97,13 @@
      */
     public static final int TYPE_ROTATION_VECTOR = 11;
 
+    /**
+     * A constant describing a relative humidity sensor type.
+     * See {@link android.hardware.SensorEvent SensorEvent}
+     * for more details.
+     */
+    public static final int TYPE_RELATIVE_HUMIDITY = 12;
+
     /** 
      * A constant describing all sensor types.
      */
diff --git a/core/java/android/hardware/SensorEvent.java b/core/java/android/hardware/SensorEvent.java
index 78d7991..9b62a68 100644
--- a/core/java/android/hardware/SensorEvent.java
+++ b/core/java/android/hardware/SensorEvent.java
@@ -304,7 +304,65 @@
      * in the clockwise direction (mathematically speaking, it should be
      * positive in the counter-clockwise direction).
      * </p>
-     * 
+     *
+     * <h4>{@link android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY
+     * Sensor.TYPE_RELATIVE_HUMIDITY}:</h4>
+     * <ul>
+     * <p>
+     * values[0]: Relative ambient air humidity in percent
+     * </p>
+     * </ul>
+     * <p>
+     * When relative ambient air humidity and ambient temperature are
+     * measured, the dew point and absolute humidity can be calculated.
+     * </p>
+     * <u>Dew Point</u>
+     * <p>
+     * The dew point is the temperature to which a given parcel of air must be
+     * cooled, at constant barometric pressure, for water vapor to condense
+     * into water.
+     * </p>
+     * <center><pre>
+     *                    ln(RH/100%) + m&#183;t/(T<sub>n</sub>+t)
+     * t<sub>d</sub>(t,RH) = T<sub>n</sub> &#183; ------------------------------
+     *                 m - [ln(RH/100%) + m&#183;t/(T<sub>n</sub>+t)]
+     * </pre></center>
+     * <dl>
+     * <dt>t<sub>d</sub></dt> <dd>dew point temperature in &deg;C</dd>
+     * <dt>t</dt>             <dd>actual temperature in &deg;C</dd>
+     * <dt>RH</dt>            <dd>actual relative humidity in %</dd>
+     * <dt>m</dt>             <dd>17.62</dd>
+     * <dt>T<sub>n</sub></dt> <dd>243.12 &deg;C</dd>
+     * </dl>
+     * <p>for example:</p>
+     * <pre class="prettyprint">
+     * h = Math.log(rh / 100.0) + (17.62 * t) / (243.12 + t);
+     * td = 243.12 * h / (17.62 - h);
+     * </pre>
+     * <u>Absolute Humidity</u>
+     * <p>
+     * The absolute humidity is the mass of water vapor in a particular volume
+     * of dry air. The unit is g/m<sup>3</sup>.
+     * </p>
+     * <center><pre>
+     *                    RH/100%&#183;A&#183;exp(m&#183;t/(T<sub>n</sub>+t))
+     * d<sub>v</sub>(t,RH) = 216.7 &#183; -------------------------
+     *                           273.15 + t
+     * </pre></center>
+     * <dl>
+     * <dt>d<sub>v</sub></dt> <dd>absolute humidity in g/m<sup>3</sup></dd>
+     * <dt>t</dt>             <dd>actual temperature in &deg;C</dd>
+     * <dt>RH</dt>            <dd>actual relative humidity in %</dd>
+     * <dt>m</dt>             <dd>17.62</dd>
+     * <dt>T<sub>n</sub></dt> <dd>243.12 &deg;C</dd>
+     * <dt>A</dt>             <dd>6.112 hPa</dd>
+     * </dl>
+     * <p>for example:</p>
+     * <pre class="prettyprint">
+     * dv = 216.7 *
+     * (rh / 100.0 * 6.112 * Math.exp(17.62 * t / (243.12 + t)) / (273.15 + t));
+     * </pre>
+     *
      * @see SensorEvent
      * @see GeomagneticField
      */
diff --git a/core/java/android/nfc/ApduList.aidl b/core/java/android/nfc/ApduList.aidl
new file mode 100644
index 0000000..f6236b2
--- /dev/null
+++ b/core/java/android/nfc/ApduList.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package android.nfc;
+
+parcelable ApduList;
\ No newline at end of file
diff --git a/core/java/android/nfc/ApduList.java b/core/java/android/nfc/ApduList.java
new file mode 100644
index 0000000..85b0547
--- /dev/null
+++ b/core/java/android/nfc/ApduList.java
@@ -0,0 +1,68 @@
+package android.nfc;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @hide
+ */
+public class ApduList implements Parcelable {
+
+    private ArrayList<byte[]> commands = new ArrayList<byte[]>();
+
+    public ApduList() {
+    }
+
+    public void add(byte[] command) {
+        commands.add(command);
+    }
+
+    public List<byte[]> get() {
+        return commands;
+    }
+
+    public static final Parcelable.Creator<ApduList> CREATOR =
+        new Parcelable.Creator<ApduList>() {
+        @Override
+        public ApduList createFromParcel(Parcel in) {
+            return new ApduList(in);
+        }
+
+        @Override
+        public ApduList[] newArray(int size) {
+            return new ApduList[size];
+        }
+    };
+
+    private ApduList(Parcel in) {
+        int count = in.readInt();
+
+        for (int i = 0 ; i < count ; i++) {
+
+            int length = in.readInt();
+            byte[] cmd = new byte[length];
+            in.readByteArray(cmd);
+            commands.add(cmd);
+        }
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeInt(commands.size());
+
+        for (byte[] cmd : commands) {
+            dest.writeInt(cmd.length);
+            dest.writeByteArray(cmd);
+        }
+    }
+}
+
+
diff --git a/core/java/android/nfc/INfcAdapterExtras.aidl b/core/java/android/nfc/INfcAdapterExtras.aidl
index ab5c1a6..0c2a2fd 100755
--- a/core/java/android/nfc/INfcAdapterExtras.aidl
+++ b/core/java/android/nfc/INfcAdapterExtras.aidl
@@ -18,6 +18,7 @@
 
 import android.os.Bundle;
 
+
 /**
  * {@hide}
  */
@@ -26,5 +27,6 @@
     Bundle close();
     Bundle transceive(in byte[] data_in);
     int getCardEmulationRoute();
-    void setCardEmulationRoute(int route);    
+    void setCardEmulationRoute(int route);
+    void authenticate(in byte[] token);
 }
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 90e2e79..1d6bc4e2 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -1883,7 +1883,6 @@
         final int NU = uidStats.size();
         boolean didPid = false;
         long nowRealtime = SystemClock.elapsedRealtime();
-        StringBuilder sb = new StringBuilder(64);
         for (int i=0; i<NU; i++) {
             Uid uid = uidStats.valueAt(i);
             SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index 5a245f8..3f02a67 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -224,4 +224,23 @@
      */
     int getInterfaceTxThrottle(String iface);
 
+    /**
+     * Sets the name of the default interface in the DNS resolver.
+     */
+    void setDefaultInterfaceForDns(String iface);
+
+    /**
+     * Bind name servers to an interface in the DNS resolver.
+     */
+    void setDnsServersForInterface(String iface, in String[] servers);
+
+    /**
+     * Flush the DNS cache associated with the default interface
+     */
+    void flushDefaultDnsCache();
+
+    /**
+     * Flush the DNS cache associated with the specified interface
+     */
+    void flushInterfaceDnsCache(String iface);
 }
diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java
index 8204e3c..ccf642c 100644
--- a/core/java/android/os/Looper.java
+++ b/core/java/android/os/Looper.java
@@ -141,7 +141,8 @@
                     Log.wtf("Looper", "Thread identity changed from 0x"
                             + Long.toHexString(ident) + " to 0x"
                             + Long.toHexString(newIdent) + " while dispatching to "
-                            + msg.target + " " + msg.callback + " what=" + msg.what);
+                            + msg.target.getClass().getName() + " "
+                            + msg.callback + " what=" + msg.what);
                 }
                 
                 msg.recycle();
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 0c6ab9e..2bfada0 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -95,7 +95,7 @@
      * Defines the UID/GID for the NFC service process.
      * @hide
      */
-    public static final int NFC_UID = 1022;
+    public static final int NFC_UID = 1025;
 
     /**
      * Defines the GID for the group that allows write access to the internal media storage.
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index 4991914..c1dd911 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -16,6 +16,11 @@
 
 package android.os;
 
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -37,9 +42,6 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
-import android.content.Context;
-import android.util.Log;
-
 import org.apache.harmony.security.asn1.BerInputStream;
 import org.apache.harmony.security.pkcs7.ContentInfo;
 import org.apache.harmony.security.pkcs7.SignedData;
@@ -336,8 +338,21 @@
      * @throws IOException  if writing the recovery command file
      * fails, or if the reboot itself fails.
      */
-    public static void rebootWipeUserData(Context context)
-        throws IOException {
+    public static void rebootWipeUserData(Context context) throws IOException {
+        final ConditionVariable condition = new ConditionVariable();
+
+        Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
+        context.sendOrderedBroadcast(intent, android.Manifest.permission.MASTER_CLEAR,
+                new BroadcastReceiver() {
+                    @Override
+                    public void onReceive(Context context, Intent intent) {
+                        condition.open();
+                    }
+                }, null, 0, null, null);
+
+        // Block until the ordered broadcast has completed.
+        condition.block();
+
         bootCommand(context, "--wipe_data");
     }
 
diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java
index d2d2557..3a06b61 100644
--- a/core/java/android/provider/Telephony.java
+++ b/core/java/android/provider/Telephony.java
@@ -542,7 +542,7 @@
              * values:</p>
              *
              * <ul>
-             *   <li><em>pdus</em> - An Object[] od byte[]s containing the PDUs
+             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
              *   that make up the message.</li>
              * </ul>
              *
@@ -586,6 +586,46 @@
                     "android.provider.Telephony.WAP_PUSH_RECEIVED";
 
             /**
+             * Broadcast Action: A new Cell Broadcast message has been received
+             * by the device. The intent will have the following extra
+             * values:</p>
+             *
+             * <ul>
+             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
+             *   that make up the message.</li>
+             * </ul>
+             *
+             * <p>The extra values can be extracted using
+             * {@link #getMessagesFromIntent(Intent)}.</p>
+             *
+             * <p>If a BroadcastReceiver encounters an error while processing
+             * this intent it should set the result code appropriately.</p>
+             */
+            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+            public static final String SMS_CB_RECEIVED_ACTION =
+                    "android.provider.Telephony.SMS_CB_RECEIVED";
+
+            /**
+             * Broadcast Action: A new Emergency Broadcast message has been received
+             * by the device. The intent will have the following extra
+             * values:</p>
+             *
+             * <ul>
+             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
+             *   that make up the message.</li>
+             * </ul>
+             *
+             * <p>The extra values can be extracted using
+             * {@link #getMessagesFromIntent(Intent)}.</p>
+             *
+             * <p>If a BroadcastReceiver encounters an error while processing
+             * this intent it should set the result code appropriately.</p>
+             */
+            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+            public static final String SMS_EMERGENCY_CB_RECEIVED_ACTION =
+                    "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED";
+
+            /**
              * Broadcast Action: The SIM storage for SMS messages is full.  If
              * space is not freed, messages targeted for the SIM (class 2) may
              * not be saved.
@@ -618,7 +658,7 @@
              * @param intent the intent to read from
              * @return an array of SmsMessages for the PDUs
              */
-            public static final SmsMessage[] getMessagesFromIntent(
+            public static SmsMessage[] getMessagesFromIntent(
                     Intent intent) {
                 Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
                 byte[][] pduObjs = new byte[messages.length][];
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
old mode 100644
new mode 100755
index f98d275..b3cbf50
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -1104,7 +1104,7 @@
     }
 
     /*package*/ synchronized boolean setBondState(String address, int state, int reason) {
-        mBondState.setBondState(address.toUpperCase(), state);
+        mBondState.setBondState(address.toUpperCase(), state, reason);
         return true;
     }
 
diff --git a/core/java/android/speech/RecognitionService.java b/core/java/android/speech/RecognitionService.java
index 75a5ed5..32b2d8f 100644
--- a/core/java/android/speech/RecognitionService.java
+++ b/core/java/android/speech/RecognitionService.java
@@ -68,6 +68,8 @@
 
     private static final int MSG_CANCEL = 3;
 
+    private static final int MSG_RESET = 4;
+
     private final Handler mHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
@@ -81,6 +83,10 @@
                     break;
                 case MSG_CANCEL:
                     dispatchCancel((IRecognitionListener) msg.obj);
+                    break;
+                case MSG_RESET:
+                    dispatchClearCallback();
+                    break;
             }
         }
     };
@@ -128,6 +134,10 @@
         }
     }
 
+    private void dispatchClearCallback() {
+        mCurrentCallback = null;
+    }
+
     private class StartListeningArgs {
         public final Intent mIntent;
 
@@ -241,7 +251,7 @@
          * @param error code is defined in {@link SpeechRecognizer}
          */
         public void error(int error) throws RemoteException {
-            mCurrentCallback = null;
+            Message.obtain(mHandler, MSG_RESET).sendToTarget();
             mListener.onError(error);
         }
 
@@ -278,7 +288,7 @@
          *        {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter
          */
         public void results(Bundle results) throws RemoteException {
-            mCurrentCallback = null;
+            Message.obtain(mHandler, MSG_RESET).sendToTarget();
             mListener.onResults(results);
         }
 
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index 1e4cca9..4107c5a 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -1170,7 +1170,7 @@
         if (h2 < 0.5f)
             h2 = 0.5f;
 
-        if (h1 == h2) {
+        if (Float.compare(h1, h2) == 0) {
             dest.moveTo(h1, top);
             dest.lineTo(h1, bottom);
         } else {
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java
index d5010c6..cdb7228 100644
--- a/core/java/android/text/TextUtils.java
+++ b/core/java/android/text/TextUtils.java
@@ -624,10 +624,16 @@
         public  CharSequence createFromParcel(Parcel p) {
             int kind = p.readInt();
 
-            if (kind == 1)
-                return p.readString();
+            String string = p.readString();
+            if (string == null) {
+                return null;
+            }
 
-            SpannableString sp = new SpannableString(p.readString());
+            if (kind == 1) {
+                return string;
+            }
+
+            SpannableString sp = new SpannableString(string);
 
             while (true) {
                 kind = p.readInt();
diff --git a/core/java/android/text/method/MultiTapKeyListener.java b/core/java/android/text/method/MultiTapKeyListener.java
index 6d94788..2a739fa 100644
--- a/core/java/android/text/method/MultiTapKeyListener.java
+++ b/core/java/android/text/method/MultiTapKeyListener.java
@@ -116,7 +116,7 @@
                     content.replace(selStart, selEnd,
                                     String.valueOf(current).toUpperCase());
                     removeTimeouts(content);
-                    Timeout t = new Timeout(content);
+                    new Timeout(content); // for its side effects
 
                     return true;
                 }
@@ -124,7 +124,7 @@
                     content.replace(selStart, selEnd,
                                     String.valueOf(current).toLowerCase());
                     removeTimeouts(content);
-                    Timeout t = new Timeout(content);
+                    new Timeout(content); // for its side effects
 
                     return true;
                 }
@@ -140,7 +140,7 @@
 
                     content.replace(selStart, selEnd, val, ix, ix + 1);
                     removeTimeouts(content);
-                    Timeout t = new Timeout(content);
+                    new Timeout(content); // for its side effects
 
                     return true;
                 }
@@ -206,7 +206,7 @@
             }
 
             removeTimeouts(content);
-            Timeout t = new Timeout(content);
+            new Timeout(content); // for its side effects
 
             // Set up the callback so we can remove the timeout if the
             // cursor moves.
diff --git a/core/java/android/text/style/DrawableMarginSpan.java b/core/java/android/text/style/DrawableMarginSpan.java
index 3c471a5..c2564d5 100644
--- a/core/java/android/text/style/DrawableMarginSpan.java
+++ b/core/java/android/text/style/DrawableMarginSpan.java
@@ -50,9 +50,6 @@
         int dw = mDrawable.getIntrinsicWidth();
         int dh = mDrawable.getIntrinsicHeight();
 
-        if (dir < 0)
-            x -= dw;
-
         // XXX What to do about Paint?
         mDrawable.setBounds(ix, itop, ix+dw, itop+dh);
         mDrawable.draw(c);
diff --git a/core/java/android/text/util/Rfc822Tokenizer.java b/core/java/android/text/util/Rfc822Tokenizer.java
index 69cf93c..68334e4 100644
--- a/core/java/android/text/util/Rfc822Tokenizer.java
+++ b/core/java/android/text/util/Rfc822Tokenizer.java
@@ -256,7 +256,7 @@
                     if (c == '"') {
                         i++;
                         break;
-                    } else if (c == '\\') {
+                    } else if (c == '\\' && i + 1 < len) {
                         i += 2;
                     } else {
                         i++;
@@ -275,7 +275,7 @@
                     } else if (c == '(') {
                         level++;
                         i++;
-                    } else if (c == '\\') {
+                    } else if (c == '\\' && i + 1 < len) {
                         i += 2;
                     } else {
                         i++;
diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java
old mode 100644
new mode 100755
index c1e1049..79b3d42
--- a/core/java/android/view/GestureDetector.java
+++ b/core/java/android/view/GestureDetector.java
@@ -193,10 +193,8 @@
         }
     }
 
-    // TODO: ViewConfiguration
-    private int mBiggerTouchSlopSquare = 20 * 20;
-
     private int mTouchSlopSquare;
+    private int mLargeTouchSlopSquare;
     private int mDoubleTapSlopSquare;
     private int mMinimumFlingVelocity;
     private int mMaximumFlingVelocity;
@@ -384,10 +382,11 @@
         mIgnoreMultitouch = ignoreMultitouch;
 
         // Fallback to support pre-donuts releases
-        int touchSlop, doubleTapSlop;
+        int touchSlop, largeTouchSlop, doubleTapSlop;
         if (context == null) {
             //noinspection deprecation
             touchSlop = ViewConfiguration.getTouchSlop();
+            largeTouchSlop = touchSlop + 2;
             doubleTapSlop = ViewConfiguration.getDoubleTapSlop();
             //noinspection deprecation
             mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
@@ -395,11 +394,13 @@
         } else {
             final ViewConfiguration configuration = ViewConfiguration.get(context);
             touchSlop = configuration.getScaledTouchSlop();
+            largeTouchSlop = configuration.getScaledLargeTouchSlop();
             doubleTapSlop = configuration.getScaledDoubleTapSlop();
             mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
             mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();
         }
         mTouchSlopSquare = touchSlop * touchSlop;
+        mLargeTouchSlopSquare = largeTouchSlop * largeTouchSlop;
         mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
     }
 
@@ -534,7 +535,7 @@
                     mHandler.removeMessages(SHOW_PRESS);
                     mHandler.removeMessages(LONG_PRESS);
                 }
-                if (distance > mBiggerTouchSlopSquare) {
+                if (distance > mLargeTouchSlopSquare) {
                     mAlwaysInBiggerTapRegion = false;
                 }
             } else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1)) {
diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java
old mode 100644
new mode 100755
index 392797c..df8f7d6
--- a/core/java/android/view/ViewConfiguration.java
+++ b/core/java/android/view/ViewConfiguration.java
@@ -143,6 +143,12 @@
     private static final int TOUCH_SLOP = 16;
     
     /**
+     * Distance a touch can wander before we think the user is the first touch
+     * in a sequence of double tap
+     */
+    private static final int LARGE_TOUCH_SLOP = 18;
+
+    /**
      * Distance a touch can wander before we think the user is attempting a paged scroll
      * (in dips)
      */
@@ -197,6 +203,7 @@
     private final int mMaximumFlingVelocity;
     private final int mScrollbarSize;
     private final int mTouchSlop;
+    private final int mLargeTouchSlop;
     private final int mPagingTouchSlop;
     private final int mDoubleTapSlop;
     private final int mWindowTouchSlop;
@@ -218,6 +225,7 @@
         mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
         mScrollbarSize = SCROLL_BAR_SIZE;
         mTouchSlop = TOUCH_SLOP;
+        mLargeTouchSlop = LARGE_TOUCH_SLOP;
         mPagingTouchSlop = PAGING_TOUCH_SLOP;
         mDoubleTapSlop = DOUBLE_TAP_SLOP;
         mWindowTouchSlop = WINDOW_TOUCH_SLOP;
@@ -254,6 +262,7 @@
         mMaximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);
         mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
         mTouchSlop = (int) (sizeAndDensity * TOUCH_SLOP + 0.5f);
+        mLargeTouchSlop =  (int) (sizeAndDensity * LARGE_TOUCH_SLOP + 0.5f);
         mPagingTouchSlop = (int) (sizeAndDensity * PAGING_TOUCH_SLOP + 0.5f);
         mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);
         mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f);
@@ -450,6 +459,14 @@
     }
     
     /**
+     * @return Distance a touch can wander before we think the user is the first touch
+     *         in a sequence of double tap
+     */
+    public int getScaledLargeTouchSlop() {
+        return mLargeTouchSlop;
+    }
+
+    /**
      * @return Distance a touch can wander before we think the user is scrolling a full page
      *         in dips
      */
diff --git a/core/java/android/webkit/CacheManager.java b/core/java/android/webkit/CacheManager.java
index 3ce0730..e21a02e 100644
--- a/core/java/android/webkit/CacheManager.java
+++ b/core/java/android/webkit/CacheManager.java
@@ -857,6 +857,7 @@
         String cacheControl = headers.getCacheControl();
         if (cacheControl != null) {
             String[] controls = cacheControl.toLowerCase().split("[ ,;]");
+            boolean noCache = false;
             for (int i = 0; i < controls.length; i++) {
                 if (NO_STORE.equals(controls[i])) {
                     return null;
@@ -867,7 +868,12 @@
                 // can only be used in CACHE_MODE_CACHE_ONLY case
                 if (NO_CACHE.equals(controls[i])) {
                     ret.expires = 0;
-                } else if (controls[i].startsWith(MAX_AGE)) {
+                    noCache = true;
+                // if cache control = no-cache has been received, ignore max-age
+                // header, according to http spec:
+                // If a request includes the no-cache directive, it SHOULD NOT
+                // include min-fresh, max-stale, or max-age.
+                } else if (controls[i].startsWith(MAX_AGE) && !noCache) {
                     int separator = controls[i].indexOf('=');
                     if (separator < 0) {
                         separator = controls[i].indexOf(':');
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index b884853..8e57260 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -1241,7 +1241,7 @@
      */
     @Deprecated
     public synchronized void setPluginsEnabled(boolean flag) {
-        setPluginState(PluginState.ON);
+        setPluginState(flag ? PluginState.ON : PluginState.OFF);
     }
 
     /**
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index 4fcd7a9..a5b7281 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -1488,6 +1488,10 @@
         @Override
         public boolean dispatchKeyEvent(KeyEvent event) {
             if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
+                if (getKeyDispatcherState() == null) {
+                    return super.dispatchKeyEvent(event);
+                }
+
                 if (event.getAction() == KeyEvent.ACTION_DOWN
                         && event.getRepeatCount() == 0) {
                     KeyEvent.DispatcherState state = getKeyDispatcherState();
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 4b4f5f2..ade3a0a 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -873,7 +873,7 @@
             int count = getChildCount();
             if (count > 0) {
                 View view = getChildAt(count - 1);
-                mTempRect.bottom = view.getBottom();
+                mTempRect.bottom = view.getBottom() + mPaddingBottom;
                 mTempRect.top = mTempRect.bottom - height;
             }
         }
@@ -949,9 +949,7 @@
             } else if (direction == View.FOCUS_DOWN) {
                 if (getChildCount() > 0) {
                     int daBottom = getChildAt(0).getBottom();
-
-                    int screenBottom = getScrollY() + getHeight();
-
+                    int screenBottom = getScrollY() + getHeight() - mPaddingBottom;
                     if (daBottom - screenBottom < maxJump) {
                         scrollDelta = daBottom - screenBottom;
                     }
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index d86504d..2847cf3 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -4708,7 +4708,7 @@
         mHistory = mHistoryEnd = mHistoryCache = null;
         mHistoryBaseTime = 0;
         long time;
-        while ((time=in.readLong()) >= 0) {
+        while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) {
             HistoryItem rec = new HistoryItem(time, in);
             addHistoryRecordLocked(rec);
             if (rec.time > mHistoryBaseTime) {
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index b549098..91a1935 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -101,6 +101,7 @@
 	android/graphics/Movie.cpp \
 	android/graphics/NinePatch.cpp \
 	android/graphics/NinePatchImpl.cpp \
+	android/graphics/NinePatchPeeker.cpp \
 	android/graphics/Paint.cpp \
 	android/graphics/Path.cpp \
 	android/graphics/PathMeasure.cpp \
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 8064836..41ab254 100644
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -271,7 +271,8 @@
 // These must match the int values in Bitmap.java

 enum JavaEncodeFormat {

     kJPEG_JavaEncodeFormat = 0,

-    kPNG_JavaEncodeFormat = 1

+    kPNG_JavaEncodeFormat = 1,

+    kWEBP_JavaEncodeFormat = 2

 };

 

 static bool Bitmap_compress(JNIEnv* env, jobject clazz, SkBitmap* bitmap,

@@ -286,6 +287,9 @@
     case kPNG_JavaEncodeFormat:

         fm = SkImageEncoder::kPNG_Type;

         break;

+    case kWEBP_JavaEncodeFormat:

+        fm = SkImageEncoder::kWEBP_Type;

+        break;

     default:

         return false;

     }

diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index 0cdb357..78fc1df 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -72,20 +72,6 @@
     static jboolean isOpaque(JNIEnv* env, jobject jcanvas) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
         SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
-
-        /*
-            Currently we cannot support transparency in GL-based canvas' at
-            the view level. Therefore we cannot base our answer on the device's
-            bitmap, but need to hard-code the answer. If we relax this
-            limitation in views, we can simplify the following code as well.
-         
-            Use the getViewport() call to find out if we're gl-based...
-        */
-        if (canvas->getViewport(NULL)) {
-            return true;
-        }
-        
-        // normal technique, rely on the device's bitmap for the answer
         return canvas->getDevice()->accessBitmap(false).isOpaque();
     }
     
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index de18f9f..d1a5546 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -115,6 +115,10 @@
     return create_jmovie(env, moov);
 }
 
+static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
+    delete movie;
+}
+
 //////////////////////////////////////////////////////////////////////////////////////////////
 
 #include <android_runtime/AndroidRuntime.h>
@@ -129,6 +133,7 @@
                             (void*)movie_draw  },
     { "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
                             (void*)movie_decodeStream },
+    { "nativeDestructor","(I)V", (void*)movie_destructor },
     { "decodeByteArray", "([BII)Landroid/graphics/Movie;",
                             (void*)movie_decodeByteArray },
 };
diff --git a/core/jni/android/graphics/NinePatchImpl.cpp b/core/jni/android/graphics/NinePatchImpl.cpp
index ff24a87..a3e36ee 100644
--- a/core/jni/android/graphics/NinePatchImpl.cpp
+++ b/core/jni/android/graphics/NinePatchImpl.cpp
@@ -116,9 +116,9 @@
         paint = &defaultPaint;
     }
     
-    // if our canvas is GL, draw this as a mesh, which will be faster than
-    // in parts (which is faster for raster)
-    if (canvas && canvas->getViewport(NULL)) {
+    // if our SkCanvas were back by GL we should enable this and draw this as
+    // a mesh, which will be faster in most cases.
+    if (false) {
         SkNinePatch::DrawMesh(canvas, bounds, bitmap,
                               chunk.xDivs, chunk.numXDivs,
                               chunk.yDivs, chunk.numYDivs,
diff --git a/core/jni/android/graphics/NinePatchPeeker.cpp b/core/jni/android/graphics/NinePatchPeeker.cpp
new file mode 100644
index 0000000..365d985
--- /dev/null
+++ b/core/jni/android/graphics/NinePatchPeeker.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NinePatchPeeker.h"
+
+#include "SkBitmap.h"
+
+using namespace android;
+
+bool NinePatchPeeker::peek(const char tag[], const void* data, size_t length) {
+    if (strcmp("npTc", tag) == 0 && length >= sizeof(Res_png_9patch)) {
+        Res_png_9patch* patch = (Res_png_9patch*) data;
+        size_t patchSize = patch->serializedSize();
+        assert(length == patchSize);
+        // You have to copy the data because it is owned by the png reader
+        Res_png_9patch* patchNew = (Res_png_9patch*) malloc(patchSize);
+        memcpy(patchNew, patch, patchSize);
+        // this relies on deserialization being done in place
+        Res_png_9patch::deserialize(patchNew);
+        patchNew->fileToDevice();
+        if (fPatchIsValid) {
+            free(fPatch);
+        }
+        fPatch = patchNew;
+        //printf("9patch: (%d,%d)-(%d,%d)\n",
+        //       fPatch.sizeLeft, fPatch.sizeTop,
+        //       fPatch.sizeRight, fPatch.sizeBottom);
+        fPatchIsValid = true;
+
+        // now update our host to force index or 32bit config
+        // 'cause we don't want 565 predithered, since as a 9patch, we know
+        // we will be stretched, and therefore we want to dither afterwards.
+        static const SkBitmap::Config gNo565Pref[] = {
+            SkBitmap::kIndex8_Config,
+            SkBitmap::kIndex8_Config,
+            SkBitmap::kARGB_8888_Config,
+            SkBitmap::kARGB_8888_Config,
+            SkBitmap::kARGB_8888_Config,
+            SkBitmap::kARGB_8888_Config,
+        };
+        fHost->setPrefConfigTable(gNo565Pref);
+    } else {
+        fPatch = NULL;
+    }
+    return true;    // keep on decoding
+}
diff --git a/core/jni/android/graphics/NinePatchPeeker.h b/core/jni/android/graphics/NinePatchPeeker.h
new file mode 100644
index 0000000..8567e23
--- /dev/null
+++ b/core/jni/android/graphics/NinePatchPeeker.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011 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 NinePatchPeeker_h
+#define NinePatchPeeker_h
+
+#include "SkImageDecoder.h"
+#include <utils/ResourceTypes.h>
+
+using namespace android;
+
+class NinePatchPeeker : public SkImageDecoder::Peeker {
+    SkImageDecoder* fHost;
+public:
+    NinePatchPeeker(SkImageDecoder* host) {
+        // the host lives longer than we do, so a raw ptr is safe
+        fHost = host;
+        fPatchIsValid = false;
+    }
+
+    ~NinePatchPeeker() {
+        if (fPatchIsValid) {
+            free(fPatch);
+        }
+    }
+
+    bool    fPatchIsValid;
+    Res_png_9patch*  fPatch;
+
+    virtual bool peek(const char tag[], const void* data, size_t length);
+};
+
+#endif // NinePatchPeeker_h
diff --git a/core/jni/android_bluetooth_BluetoothSocket.cpp b/core/jni/android_bluetooth_BluetoothSocket.cpp
index b87f7c4..d09c4e9 100644
--- a/core/jni/android_bluetooth_BluetoothSocket.cpp
+++ b/core/jni/android_bluetooth_BluetoothSocket.cpp
@@ -448,7 +448,7 @@
 #ifdef HAVE_BLUETOOTH
     LOGV("%s", __FUNCTION__);
 
-    int ret;
+    int ret, total;
     jbyte *b;
     int sz;
     struct asocket *s = get_socketData(env, obj);
@@ -471,15 +471,21 @@
         return -1;
     }
 
-    ret = asocket_write(s, &b[offset], length, -1);
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        env->ReleaseByteArrayElements(jb, b, JNI_ABORT);
-        return -1;
+    total = 0;
+    while (length > 0) {
+        ret = asocket_write(s, &b[offset], length, -1);
+        if (ret < 0) {
+            jniThrowIOException(env, errno);
+            env->ReleaseByteArrayElements(jb, b, JNI_ABORT);
+            return -1;
+        }
+        offset += ret;
+        total += ret;
+        length -= ret;
     }
 
     env->ReleaseByteArrayElements(jb, b, JNI_ABORT);  // no need to commit
-    return (jint)ret;
+    return (jint)total;
 
 #endif
     jniThrowIOException(env, ENOSYS);
diff --git a/core/jni/android_nfc_NdefMessage.cpp b/core/jni/android_nfc_NdefMessage.cpp
index 9beef2a..aff8aa6 100644
--- a/core/jni/android_nfc_NdefMessage.cpp
+++ b/core/jni/android_nfc_NdefMessage.cpp
@@ -102,6 +102,19 @@
         }
         TRACE("phFriNfc_NdefRecord_Parse() returned 0x%04x", status);
 
+        // We don't exactly know what *is* a valid length, but a simple
+        // sanity check is to make sure that the length of the header
+        // plus all fields does not exceed raw_msg_size. The min length
+        // of the header is 3 bytes: TNF, Type Length, Payload Length
+        // (ID length field is optional!)
+        uint64_t indicatedMsgLength = 3 + record.TypeLength + record.IdLength +
+                (uint64_t)record.PayloadLength;
+        if (indicatedMsgLength >
+                (uint64_t)raw_msg_size) {
+            LOGE("phFri_NdefRecord_Parse: invalid length field");
+            goto end;
+        }
+
         type = e->NewByteArray(record.TypeLength);
         if (type == NULL) {
             LOGD("NFC_Set Record Type Error\n");
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index afaade8..a6bde88 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -351,7 +351,7 @@
 {
     DBusMessage *msg, *reply;
     DBusError err;
-    bool oob = TRUE;
+    dbus_bool_t oob = TRUE;
 
     if (!dbus_connection_register_object_path(nat->conn, agent_path,
             &agent_vtable, nat)) {
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 4d40b57..8273bbd 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -57,6 +57,7 @@
     <protected-broadcast android:name="android.intent.action.NEW_OUTGOING_CALL" />
     <protected-broadcast android:name="android.intent.action.REBOOT" />
     <protected-broadcast android:name="android.intent.action.DOCK_EVENT" />
+    <protected-broadcast android:name="android.intent.action.MASTER_CLEAR_NOTIFICATION" />
 
     <protected-broadcast android:name="android.app.action.ENTER_CAR_MODE" />
     <protected-broadcast android:name="android.app.action.EXIT_CAR_MODE" />
@@ -158,6 +159,15 @@
         android:label="@string/permlab_receiveMms"
         android:description="@string/permdesc_receiveMms" />
 
+    <!-- Allows an application to receive emergency cell broadcast messages,
+         to record or display them to the user. Reserved for system apps.
+         @hide Pending API council approval -->
+    <permission android:name="android.permission.RECEIVE_EMERGENCY_BROADCAST"
+        android:permissionGroup="android.permission-group.MESSAGES"
+        android:protectionLevel="signatureOrSystem"
+        android:label="@string/permlab_receiveEmergencyBroadcast"
+        android:description="@string/permdesc_receiveEmergencyBroadcast" />
+
     <!-- Allows an application to read SMS messages. -->
     <permission android:name="android.permission.READ_SMS"
         android:permissionGroup="android.permission-group.MESSAGES"
@@ -1045,7 +1055,7 @@
     <permission android:name="android.permission.STOP_APP_SWITCHES"
         android:label="@string/permlab_stopAppSwitches"
         android:description="@string/permdesc_stopAppSwitches"
-        android:protectionLevel="signature" />
+        android:protectionLevel="signatureOrSystem" />
 
     <!-- Allows an application to retrieve the current state of keys and
          switches.  This is only for use by the system.-->
diff --git a/core/res/res/values-hr/strings.xml b/core/res/res/values-hr/strings.xml
index 8f37331..98eb4b4 100644
--- a/core/res/res/values-hr/strings.xml
+++ b/core/res/res/values-hr/strings.xml
@@ -190,6 +190,8 @@
     <string name="permdesc_receiveSms" msgid="6298292335965966117">"Aplikaciji omogućuje primanje i obradu SMS poruka. Zlonamjerne aplikacije mogu pratiti vaše poruke ili ih izbrisati prije nego što ih vi vidite."</string>
     <string name="permlab_receiveMms" msgid="8894700916188083287">"primanje MMS-a"</string>
     <string name="permdesc_receiveMms" msgid="4563346832000174373">"Aplikaciji omogućuje primanje i obradu MMS poruka. Zlonamjerne aplikacije mogu pratiti vaše poruke ili ih izbrisati prije nego što ih vi vidite."</string>
+    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"primanje hitnih odašiljanja"</string>
+    <string name="permdesc_receiveEmergencyBroadcast" msgid="7118393393716546131">"Omogućuje aplikaciji primanje i obradu poruka hitnih odašiljanja. Ta je dozvola dostupna samo aplikacijama sustava."</string>
     <string name="permlab_sendSms" msgid="5600830612147671529">"slanje SMS poruka"</string>
     <string name="permdesc_sendSms" msgid="1946540351763502120">"Aplikaciji omogućuje slanje SMS poruka. Zlonamjerne aplikacije mogu stvarati troškove slanjem poruka bez vaše potvrde."</string>
     <string name="permlab_readSms" msgid="4085333708122372256">"čitanje SMS-a ili MMS-a"</string>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index f49be42..16e443b 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -575,4 +575,68 @@
          If false, mms read reports are not supported and the preference
          option to enable/disable read reports is removed in the Messaging app. -->
     <bool name="config_mms_read_reports_support">true</bool>
+
+    <!-- National Language Identifier codes for the following two config items.
+         (from 3GPP TS 23.038 V9.1.1 Table 6.2.1.2.4.1):
+          0  - reserved
+          1  - Turkish
+          2  - Spanish (single shift table only)
+          3  - Portuguese
+          4  - Bengali
+          5  - Gujarati
+          6  - Hindi
+          7  - Kannada
+          8  - Malayalam
+          9  - Oriya
+         10  - Punjabi
+         11  - Tamil
+         12  - Telugu
+         13  - Urdu
+         14+ - reserved -->
+
+    <!-- National language single shift tables to enable for SMS encoding.
+         Decoding is always enabled. 3GPP TS 23.038 states that this feature
+         should not be enabled until a formal request is issued by the relevant
+         national regulatory body. Array elements are codes from the table above.
+         Example 1: devices sold in Turkey must include table 1 to conform with
+           By-Law Number 27230. (http://www.btk.gov.tr/eng/pdf/2009/BY-LAW_SMS.pdf)
+         Example 2: devices sold in India should include tables 4 through 13
+           to enable use of the new Release 9 tables for Indic languages. -->
+    <integer-array name="config_sms_enabled_single_shift_tables"></integer-array>
+
+    <!-- National language locking shift tables to enable for SMS encoding.
+         Decoding is always enabled. 3GPP TS 23.038 states that this feature
+         should not be enabled until a formal request is issued by the relevant
+         national regulatory body. Array elements are codes from the table above.
+         Example 1: devices sold in Turkey must include table 1 after the
+           Turkish Telecommunication Authority requires locking shift encoding
+           to be enabled (est. July 2012). (http://www.btk.gov.tr/eng/pdf/2009/BY-LAW_SMS.pdf)
+           See also: http://www.mobitech.com.tr/tr/ersanozturkblog_en/index.php?entry=entry090223-160014
+         Example 2: devices sold in India should include tables 4 through 13
+         to enable use of the new Release 9 tables for Indic languages. -->
+    <integer-array name="config_sms_enabled_locking_shift_tables"></integer-array>
+
+    <!-- Set and Unsets WiMAX -->
+    <bool name="config_wimaxEnabled">false</bool>
+    <!-- Location of the wimax framwork jar location -->
+    <string name="config_wimaxServiceJarLocation"></string>
+    <!-- Location of the wimax native library locaiton -->
+    <string name="config_wimaxNativeLibLocation"></string>
+    <!-- Name of the wimax manager class -->
+    <string name="config_wimaxManagerClassname"></string>
+    <!-- Name of the wimax service class -->
+    <string name="config_wimaxServiceClassname"></string>
+    <!-- Name of the wimax state tracker clas -->
+    <string name="config_wimaxStateTrackerClassname"></string>
+
+    <!-- Set to true if the RSSI should always display CDMA signal strength
+         even on EVDO -->
+    <bool name="config_alwaysUseCdmaRssi">false</bool>
+
+    <!-- If this value is true, duplicate Source/Destination port fields
+         in WDP header of some carriers OMADM wap push are supported.
+         ex: MSGTYPE-TotalSegments-CurrentSegment
+             -SourcePortDestPort-SourcePortDestPort-OMADM PDU
+         If false, not supported. -->
+    <bool name="config_duplicate_port_omadm_wappush">false</bool>
 </resources>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 48731b9..f24670c 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -459,6 +459,13 @@
       your messages or delete them without showing them to you.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permlab_receiveEmergencyBroadcast">receive emergency broadcasts</string>
+    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+    <string name="permdesc_receiveEmergencyBroadcast">Allows application to receive
+      and process emergency broadcast messages. This permission is only available
+      to system applications.</string>
+
+     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_sendSms">send SMS messages</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_sendSms">Allows application to send SMS
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index 4be6995..fadf1ec 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -100,6 +100,12 @@
 
     <application android:theme="@style/Theme">
         <uses-library android:name="android.test.runner" />
+        <activity android:name="android.view.ViewAttachTestActivity" android:label="View Attach Test">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
         <activity android:name="StubTestBrowserActivity" android:label="Stubbed Test Browser">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN"/>
@@ -415,6 +421,13 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="android.widget.scroll.arrowscroll.MultiPageTextWithPadding" android:label="arrowscrollMultiPageTextWithPadding">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="android.view.Include" android:label="IncludeTag">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/core/tests/coretests/res/layout/attach_view_test.xml b/core/tests/coretests/res/layout/attach_view_test.xml
new file mode 100644
index 0000000..42841cb
--- /dev/null
+++ b/core/tests/coretests/res/layout/attach_view_test.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent">
+    <android.view.ViewAttachView
+    android:id="@+id/view_attach_view"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:keepScreenOn="true"/>
+</LinearLayout>
diff --git a/core/tests/coretests/src/android/content/pm/PackageHelperTests.java b/core/tests/coretests/src/android/content/pm/PackageHelperTests.java
new file mode 100644
index 0000000..27112a6
--- /dev/null
+++ b/core/tests/coretests/src/android/content/pm/PackageHelperTests.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package android.content.pm;
+
+import com.android.internal.content.PackageHelper;
+
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.storage.IMountService;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+public class PackageHelperTests extends AndroidTestCase {
+    private static final boolean localLOGV = true;
+    public static final String TAG = "PackageHelperTests";
+    protected final String PREFIX = "android.content.pm";
+    private IMountService mMs;
+    private String fullId;
+    private String fullId2;
+
+    private IMountService getMs() {
+        IBinder service = ServiceManager.getService("mount");
+        if (service != null) {
+            return IMountService.Stub.asInterface(service);
+        } else {
+            Log.e(TAG, "Can't get mount service");
+        }
+        return null;
+    }
+
+    private void cleanupContainers() throws RemoteException {
+        Log.d(TAG,"cleanUp");
+        IMountService ms = getMs();
+        String[] containers = ms.getSecureContainerList();
+        for (int i = 0; i < containers.length; i++) {
+            if (containers[i].startsWith(PREFIX)) {
+                Log.d(TAG,"cleaing up "+containers[i]);
+                ms.destroySecureContainer(containers[i], true);
+            }
+        }
+    }
+
+    void failStr(String errMsg) {
+        Log.w(TAG, "errMsg=" + errMsg);
+        fail(errMsg);
+    }
+
+    void failStr(Exception e) {
+        failStr(e.getMessage());
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (localLOGV) Log.i(TAG, "Cleaning out old test containers");
+        cleanupContainers();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (localLOGV) Log.i(TAG, "Cleaning out old test containers");
+        cleanupContainers();
+    }
+
+    public void testMountAndPullSdCard() {
+        try {
+            fullId = PREFIX;
+            fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid());
+
+            Log.d(TAG,PackageHelper.getSdDir(fullId));
+            PackageHelper.unMountSdDir(fullId);
+
+            Runnable r1 = getMountRunnable();
+            Runnable r2 = getDestroyRunnable();
+            Thread thread = new Thread(r1);
+            Thread thread2 = new Thread(r2);
+            thread2.start();
+            thread.start();
+        } catch (Exception e) {
+            failStr(e);
+        }
+    }
+
+    public Runnable getMountRunnable() {
+        Runnable r = new Runnable () {
+            public void run () {
+                try {
+                    Thread.sleep(5);
+                    String path = PackageHelper.mountSdDir(fullId, "none",
+                            android.os.Process.myUid());
+                    Log.e(TAG, "mount done " + path);
+                } catch (IllegalArgumentException iae) {
+                    throw iae;
+                } catch (Throwable t) {
+                    Log.e(TAG, "mount failed", t);
+                }
+            }
+        };
+        return r;
+    }
+
+    public Runnable getDestroyRunnable() {
+        Runnable r = new Runnable () {
+            public void run () {
+                try {
+                    PackageHelper.destroySdDir(fullId);
+                    Log.e(TAG, "destroy done: " + fullId);
+                } catch (Throwable t) {
+                    Log.e(TAG, "destroy failed", t);
+                }
+            }
+        };
+        return r;
+    }
+}
diff --git a/core/tests/coretests/src/android/text/TextUtilsTest.java b/core/tests/coretests/src/android/text/TextUtilsTest.java
index e111662..63dd0cc 100644
--- a/core/tests/coretests/src/android/text/TextUtilsTest.java
+++ b/core/tests/coretests/src/android/text/TextUtilsTest.java
@@ -17,6 +17,7 @@
 package android.text;
 
 import android.graphics.Paint;
+import android.os.Parcel;
 import android.test.suitebuilder.annotation.LargeTest;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.text.Spannable;
@@ -255,6 +256,23 @@
         assertEquals("Foo Bar", tokens[0].getAddress());
     }
 
+    @SmallTest
+    public void testRfc822FindToken() {
+        Rfc822Tokenizer tokenizer = new Rfc822Tokenizer();
+        //                0           1         2           3         4
+        //                0 1234 56789012345678901234 5678 90123456789012345
+        String address = "\"Foo\" <foo@google.com>, \"Bar\" <bar@google.com>";
+        assertEquals(0, tokenizer.findTokenStart(address, 21));
+        assertEquals(22, tokenizer.findTokenEnd(address, 21));
+        assertEquals(24, tokenizer.findTokenStart(address, 25));
+        assertEquals(46, tokenizer.findTokenEnd(address, 25));
+    }
+
+    @SmallTest
+    public void testRfc822FindTokenWithError() {
+        assertEquals(9, new Rfc822Tokenizer().findTokenEnd("\"Foo Bar\\", 0));
+    }
+
     @LargeTest
     public void testEllipsize() {
         CharSequence s1 = "The quick brown fox jumps over \u00FEhe lazy dog.";
@@ -335,6 +353,51 @@
         assertFalse(TextUtils.delimitedStringContains("network,mock,gpsx", ',', "gps"));
     }
 
+    @SmallTest
+    public void testCharSequenceCreator() {
+        Parcel p = Parcel.obtain();
+        TextUtils.writeToParcel(null, p, 0);
+        CharSequence text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+        assertNull("null CharSequence should generate null from parcel", text);
+        p = Parcel.obtain();
+        TextUtils.writeToParcel("test", p, 0);
+        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+        assertEquals("conversion to/from parcel failed", "test", text);
+    }
+
+    @SmallTest
+    public void testCharSequenceCreatorNull() {
+        Parcel p;
+        CharSequence text;
+        p = Parcel.obtain();
+        TextUtils.writeToParcel(null, p, 0);
+        p.setDataPosition(0);
+        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+        assertNull("null CharSequence should generate null from parcel", text);
+    }
+
+    @SmallTest
+    public void testCharSequenceCreatorSpannable() {
+        Parcel p;
+        CharSequence text;
+        p = Parcel.obtain();
+        TextUtils.writeToParcel(new SpannableString("test"), p, 0);
+        p.setDataPosition(0);
+        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+        assertEquals("conversion to/from parcel failed", "test", text.toString());
+    }
+
+    @SmallTest
+    public void testCharSequenceCreatorString() {
+        Parcel p;
+        CharSequence text;
+        p = Parcel.obtain();
+        TextUtils.writeToParcel("test", p, 0);
+        p.setDataPosition(0);
+        text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+        assertEquals("conversion to/from parcel failed", "test", text.toString());
+    }
+
     /**
      * CharSequence wrapper for testing the cases where text is copied into
      * a char array instead of working from a String or a Spanned.
diff --git a/core/tests/coretests/src/android/util/ScrollViewScenario.java b/core/tests/coretests/src/android/util/ScrollViewScenario.java
index 83afe06..db3d9d0 100644
--- a/core/tests/coretests/src/android/util/ScrollViewScenario.java
+++ b/core/tests/coretests/src/android/util/ScrollViewScenario.java
@@ -61,6 +61,7 @@
 
     /**
      * Partially implement ViewFactory given a height ratio.
+     * A negative height ratio means that WRAP_CONTENT will be used as height
      */
     private static abstract class ViewFactoryBase implements ViewFactory {
 
@@ -87,6 +88,9 @@
 
         List<ViewFactory> mViewFactories = Lists.newArrayList();
 
+        int mTopPadding = 0;
+        int mBottomPadding = 0;
+
         /**
          * Add a text view.
          * @param text The text of the text view.
@@ -186,6 +190,13 @@
             });
             return this;
         }
+
+        public Params addPaddingToScrollView(int topPadding, int bottomPadding) {
+            mTopPadding = topPadding;
+            mBottomPadding = bottomPadding;
+
+            return this;
+        }
     }
 
     /**
@@ -239,13 +250,17 @@
 
         // create views specified by params
         for (ViewFactory viewFactory : params.mViewFactories) {
+            int height = ViewGroup.LayoutParams.WRAP_CONTENT;
+            if (viewFactory.getHeightRatio() >= 0) {
+                height = (int) (viewFactory.getHeightRatio() * screenHeight);
+            }
             final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
-                    ViewGroup.LayoutParams.MATCH_PARENT,
-                    (int) (viewFactory.getHeightRatio() * screenHeight));
+                    ViewGroup.LayoutParams.MATCH_PARENT, height);
             mLinearLayout.addView(viewFactory.create(this), lp);
         }
 
         mScrollView = createScrollView();
+        mScrollView.setPadding(0, params.mTopPadding, 0, params.mBottomPadding);
         mScrollView.addView(mLinearLayout, new ViewGroup.LayoutParams(
                 ViewGroup.LayoutParams.MATCH_PARENT,
                 ViewGroup.LayoutParams.MATCH_PARENT));
diff --git a/core/tests/coretests/src/android/view/ViewAttachTest.java b/core/tests/coretests/src/android/view/ViewAttachTest.java
new file mode 100644
index 0000000..cff66e4
--- /dev/null
+++ b/core/tests/coretests/src/android/view/ViewAttachTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package android.view;
+
+import android.content.pm.ActivityInfo;
+import android.os.SystemClock;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class ViewAttachTest extends
+        ActivityInstrumentationTestCase2<ViewAttachTestActivity> {
+
+    public ViewAttachTest() {
+        super(ViewAttachTestActivity.class);
+    }
+
+    /**
+     * Make sure that onAttachedToWindow and onDetachedToWindow is called in the
+     * correct order The ViewAttachTestActivity contains a view that will throw
+     * an RuntimeException if onDetachedToWindow and onAttachedToWindow is
+     * called in the wrong order.
+     *
+     * 1. Initiate the activity 2. Perform a series of orientation changes to
+     * the activity (this will force the View hierarchy to be rebuild,
+     * generating onAttachedToWindow and onDetachedToWindow)
+     *
+     * Expected result: No RuntimeException is thrown from the TestView in
+     * ViewFlipperTestActivity.
+     *
+     * @throws Throwable
+     */
+    public void testAttached() throws Throwable {
+        final ViewAttachTestActivity activity = getActivity();
+        for (int i = 0; i < 20; i++) {
+            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+            SystemClock.sleep(250);
+            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+            SystemClock.sleep(250);
+        }
+    }
+}
diff --git a/core/tests/coretests/src/android/view/ViewAttachTestActivity.java b/core/tests/coretests/src/android/view/ViewAttachTestActivity.java
new file mode 100644
index 0000000..59e25ae
--- /dev/null
+++ b/core/tests/coretests/src/android/view/ViewAttachTestActivity.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package android.view;
+
+import com.android.frameworks.coretests.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class ViewAttachTestActivity extends Activity {
+    public static final String TAG = "OnAttachedTest";
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.attach_view_test);
+    }
+}
diff --git a/core/tests/coretests/src/android/view/ViewAttachView.java b/core/tests/coretests/src/android/view/ViewAttachView.java
new file mode 100644
index 0000000..5af2d8f
--- /dev/null
+++ b/core/tests/coretests/src/android/view/ViewAttachView.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package android.view;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.os.SystemClock;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+
+/**
+ * A View that will throw a RuntimeException if onAttachedToWindow and
+ * onDetachedFromWindow is called in the wrong order for ViewAttachTest
+ */
+public class ViewAttachView extends View {
+    public static final String TAG = "OnAttachedTest";
+    private boolean attached;
+
+    public ViewAttachView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(attrs, defStyle);
+    }
+
+    public ViewAttachView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(attrs, 0);
+    }
+
+    public ViewAttachView(Context context) {
+        super(context);
+        init(null, 0);
+    }
+
+    private void init(AttributeSet attrs, int defStyle) {
+        SystemClock.sleep(2000);
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        Log.d(TAG, "onAttachedToWindow");
+        super.onAttachedToWindow();
+        if (attached) {
+            throw new RuntimeException("OnAttachedToWindow called more than once in a row");
+        }
+        attached = true;
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        Log.d(TAG, "onDetachedFromWindow");
+        super.onDetachedFromWindow();
+        if (!attached) {
+            throw new RuntimeException(
+                    "onDetachedFromWindowcalled without prior call to OnAttachedToWindow");
+        }
+        attached = false;
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        canvas.drawColor(Color.BLUE);
+    }
+}
diff --git a/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java
new file mode 100644
index 0000000..7d5a8d8
--- /dev/null
+++ b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package android.widget.scroll.arrowscroll;
+
+import android.util.ScrollViewScenario;
+
+/**
+ * One TextView with a text covering several pages. Padding is added
+ * above and below the ScrollView.
+ */
+public class MultiPageTextWithPadding extends ScrollViewScenario {
+
+    @Override
+    protected void init(Params params) {
+
+        String text = "This is a long text.";
+        String longText = "First text.";
+        for (int i = 0; i < 300; i++) {
+            longText = longText + " " + text;
+        }
+        longText = longText + " Last text.";
+        params.addTextView(longText, -1.0f).addPaddingToScrollView(50, 50);
+    }
+}
diff --git a/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java
new file mode 100644
index 0000000..ddde48f
--- /dev/null
+++ b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 Sony Ericsson Mobile Communications AB.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.widget.scroll.arrowscroll;
+
+import android.widget.scroll.arrowscroll.MultiPageTextWithPadding;
+import android.test.ActivityInstrumentationTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.view.KeyEvent;
+import android.widget.TextView;
+import android.widget.ScrollView;
+
+public class MultiPageTextWithPaddingTest extends
+        ActivityInstrumentationTestCase<MultiPageTextWithPadding> {
+
+    private ScrollView mScrollView;
+
+    private TextView mTextView;
+
+    public MultiPageTextWithPaddingTest() {
+        super("com.android.frameworks.coretests", MultiPageTextWithPadding.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mScrollView = getActivity().getScrollView();
+        mTextView = getActivity().getContentChildAt(0);
+    }
+
+    @MediumTest
+    public void testPreconditions() {
+        assertTrue("text should not fit on screen",
+                   mTextView.getHeight() > mScrollView.getHeight());
+    }
+
+    @LargeTest
+    public void testScrollDownToBottom() throws Exception {
+        // Calculate the number of arrow scrolls needed to reach the bottom
+        int scrollsNeeded = (int)Math.ceil(Math.max(0.0f,
+                (mTextView.getHeight() - mScrollView.getHeight()))
+                / mScrollView.getMaxScrollAmount());
+        for (int i = 0; i < scrollsNeeded; i++) {
+            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+        }
+
+        assertEquals(
+                "should be fully scrolled to bottom",
+                getActivity().getLinearLayout().getHeight()
+                        - (mScrollView.getHeight() - mScrollView.getPaddingTop() - mScrollView
+                                .getPaddingBottom()), mScrollView.getScrollY());
+    }
+}
diff --git a/core/tests/overlaytests/Android.mk b/core/tests/overlaytests/Android.mk
new file mode 100644
index 0000000..bf69442
--- /dev/null
+++ b/core/tests/overlaytests/Android.mk
@@ -0,0 +1,4 @@
+# Dummy makefile to halt recursive directory traversal.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
diff --git a/core/tests/overlaytests/OverlayTest/Android.mk b/core/tests/overlaytests/OverlayTest/Android.mk
new file mode 100644
index 0000000..f7f67f6
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTest/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_PACKAGE_NAME := OverlayTest
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+include $(BUILD_PACKAGE)
diff --git a/core/tests/overlaytests/OverlayTest/AndroidManifest.xml b/core/tests/overlaytests/OverlayTest/AndroidManifest.xml
new file mode 100644
index 0000000..9edba12
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTest/AndroidManifest.xml
@@ -0,0 +1,10 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.overlaytest">
+    <uses-permission android:name="android.permission.RUN_INSTRUMENTATION"/>
+    <application>
+        <uses-library android:name="android.test.runner"/>
+    </application>
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+        android:targetPackage="com.android.overlaytest"
+        android:label="Runtime resource overlay tests"/>
+</manifest>
diff --git a/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/OverlayBaseTest.java b/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/OverlayBaseTest.java
new file mode 100644
index 0000000..85b49ce
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/OverlayBaseTest.java
@@ -0,0 +1,118 @@
+package com.android.overlaytest;
+
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.test.AndroidTestCase;
+import java.io.InputStream;
+import java.util.Locale;
+
+public abstract class OverlayBaseTest extends AndroidTestCase {
+    private Resources mResources;
+    protected boolean mWithOverlay; // will be set by subclasses
+
+    protected void setUp() {
+        mResources = getContext().getResources();
+    }
+
+    private int calculateRawResourceChecksum(int resId) throws Throwable {
+        InputStream input = null;
+        try {
+            input = mResources.openRawResource(resId);
+            int ch, checksum = 0;
+            while ((ch = input.read()) != -1) {
+                checksum = (checksum + ch) % 0xffddbb00;
+            }
+            return checksum;
+        } finally {
+            input.close();
+        }
+    }
+
+    private void setLocale(String code) {
+        Locale locale = new Locale(code);
+        Locale.setDefault(locale);
+        Configuration config = new Configuration();
+        config.locale = locale;
+        mResources.updateConfiguration(config, mResources.getDisplayMetrics());
+    }
+
+    private void assertResource(int resId, boolean ewo, boolean ew) throws Throwable {
+        boolean expected = mWithOverlay ? ew : ewo;
+        boolean actual = mResources.getBoolean(resId);
+        assertEquals(expected, actual);
+    }
+
+    private void assertResource(int resId, String ewo, String ew) throws Throwable {
+        String expected = mWithOverlay ? ew : ewo;
+        String actual = mResources.getString(resId);
+        assertEquals(expected, actual);
+    }
+
+    private void assertResource(int resId, int[] ewo, int[] ew) throws Throwable {
+        int[] expected = mWithOverlay ? ew : ewo;
+        int[] actual = mResources.getIntArray(resId);
+        assertEquals("length:", expected.length, actual.length);
+        for (int i = 0; i < actual.length; ++i) {
+            assertEquals("index " + i + ":", actual[i], expected[i]);
+        }
+    }
+
+    public void testBooleanOverlay() throws Throwable {
+        // config_automatic_brightness_available has overlay (default config)
+        final int resId = com.android.internal.R.bool.config_automatic_brightness_available;
+        assertResource(resId, false, true);
+    }
+
+    public void testBoolean() throws Throwable {
+        // config_bypass_keyguard_if_slider_open has no overlay
+        final int resId = com.android.internal.R.bool.config_bypass_keyguard_if_slider_open;
+        assertResource(resId, true, true);
+    }
+
+    public void testStringOverlay() throws Throwable {
+        // phoneTypeCar has an overlay (default config), which shouldn't shadow
+        // the Swedish translation
+        final int resId = com.android.internal.R.string.phoneTypeCar;
+        setLocale("sv_SE");
+        assertResource(resId, "Bil", "Bil");
+    }
+
+    public void testStringSwedishOverlay() throws Throwable {
+        // phoneTypeWork has overlay (no default config, only for lang=sv)
+        final int resId = com.android.internal.R.string.phoneTypeWork;
+        setLocale("en_US");
+        assertResource(resId, "Work", "Work");
+        setLocale("sv_SE");
+        assertResource(resId, "Arbete", "Jobb");
+    }
+
+    public void testString() throws Throwable {
+        // phoneTypeHome has no overlay
+        final int resId = com.android.internal.R.string.phoneTypeHome;
+        setLocale("en_US");
+        assertResource(resId, "Home", "Home");
+        setLocale("sv_SE");
+        assertResource(resId, "Hem", "Hem");
+    }
+
+    public void testIntegerArrayOverlay() throws Throwable {
+        // config_scrollBarrierVibePattern has overlay (default config)
+        final int resId = com.android.internal.R.array.config_scrollBarrierVibePattern;
+        assertResource(resId, new int[]{0, 15, 10, 10}, new int[]{100, 200, 300});
+    }
+
+    public void testIntegerArray() throws Throwable {
+        // config_virtualKeyVibePattern has no overlay
+        final int resId = com.android.internal.R.array.config_virtualKeyVibePattern;
+        final int[] expected = {0, 10, 20, 30};
+        assertResource(resId, expected, expected);
+    }
+
+    public void testAsset() throws Throwable {
+        // drawable/default_background.jpg has overlay (default config)
+        final int resId = com.android.internal.R.drawable.default_wallpaper;
+        int actual = calculateRawResourceChecksum(resId);
+        int expected = mWithOverlay ? 0x000051da : 0x0014ebce;
+        assertEquals(expected, actual);
+    }
+}
diff --git a/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/WithOverlayTest.java b/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/WithOverlayTest.java
new file mode 100644
index 0000000..1292d03
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/WithOverlayTest.java
@@ -0,0 +1,7 @@
+package com.android.overlaytest;
+
+public class WithOverlayTest extends OverlayBaseTest {
+    public WithOverlayTest() {
+        mWithOverlay = true;
+    }
+}
diff --git a/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/WithoutOverlayTest.java b/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/WithoutOverlayTest.java
new file mode 100644
index 0000000..630ff8f
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTest/src/com/android/overlaytest/WithoutOverlayTest.java
@@ -0,0 +1,7 @@
+package com.android.overlaytest;
+
+public class WithoutOverlayTest extends OverlayBaseTest {
+    public WithoutOverlayTest() {
+        mWithOverlay = false;
+    }
+}
diff --git a/core/tests/overlaytests/OverlayTestOverlay/Android.mk b/core/tests/overlaytests/OverlayTestOverlay/Android.mk
new file mode 100644
index 0000000..cf32c9f
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTestOverlay/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_PACKAGE_NAME := com.android.overlaytest.overlay
+
+LOCAL_AAPT_FLAGS := -o
+
+include $(BUILD_PACKAGE)
diff --git a/core/tests/overlaytests/OverlayTestOverlay/AndroidManifest.xml b/core/tests/overlaytests/OverlayTestOverlay/AndroidManifest.xml
new file mode 100644
index 0000000..bcbb0d1
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTestOverlay/AndroidManifest.xml
@@ -0,0 +1,6 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.overlaytest.overlay"
+        android:versionCode="1"
+        android:versionName="1.0">
+    <overlay-package android:name="android"/>
+</manifest>
diff --git a/core/tests/overlaytests/OverlayTestOverlay/res/drawable/default_wallpaper.jpg b/core/tests/overlaytests/OverlayTestOverlay/res/drawable/default_wallpaper.jpg
new file mode 100644
index 0000000..0d944d0
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTestOverlay/res/drawable/default_wallpaper.jpg
Binary files differ
diff --git a/core/tests/overlaytests/OverlayTestOverlay/res/values-sv/config.xml b/core/tests/overlaytests/OverlayTestOverlay/res/values-sv/config.xml
new file mode 100644
index 0000000..bc52367
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTestOverlay/res/values-sv/config.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="phoneTypeWork">Jobb</string>
+</resources>
diff --git a/core/tests/overlaytests/OverlayTestOverlay/res/values/config.xml b/core/tests/overlaytests/OverlayTestOverlay/res/values/config.xml
new file mode 100644
index 0000000..794f475
--- /dev/null
+++ b/core/tests/overlaytests/OverlayTestOverlay/res/values/config.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <bool name="config_automatic_brightness_available">true</bool>
+    <string name="phoneTypeCar">Automobile</string>
+    <integer-array name="config_scrollBarrierVibePattern">
+        <item>100</item>
+        <item>200</item>
+        <item>300</item>
+    </integer-array>
+    <!-- The following integer does not exist in the original package. Idmap
+         generation should therefore ignore it. -->
+    <integer name="integer_not_in_original_package">0</integer>
+</resources>
diff --git a/core/tests/overlaytests/README b/core/tests/overlaytests/README
new file mode 100644
index 0000000..4b3e6f2
--- /dev/null
+++ b/core/tests/overlaytests/README
@@ -0,0 +1,15 @@
+Unit tests for runtime resource overlay
+=======================================
+
+As of this writing, runtime resource overlay is only triggered for
+/system/framework/framework-res.apk. Because of this, installation of
+overlay packages require the Android platform be rebooted. However, the
+regular unit tests (triggered via development/testrunner/runtest.py)
+cannot handle reboots. As a workaround, this directory contains a shell
+script which will trigger the tests in a non-standard way.
+
+Once runtime resource overlay may be applied to applications, the tests
+in this directory should be moved to core/tests/coretests. Also, by
+applying runtime resource overlay to a dedicated test application, the
+test cases would not need to assume default values for non-overlaid
+resources.
diff --git a/core/tests/overlaytests/runtests.sh b/core/tests/overlaytests/runtests.sh
new file mode 100755
index 0000000..0ad9efb
--- /dev/null
+++ b/core/tests/overlaytests/runtests.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+adb="adb"
+if [[ $# -gt 0 ]]; then
+	adb="adb $*" # for setting -e, -d or -s <serial>
+fi
+
+function atexit()
+{
+	local retval=$?
+
+	if [[ $retval -eq 0 ]]; then
+		rm $log
+	else
+		echo "There were errors, please check log at $log"
+	fi
+}
+
+log=$(mktemp)
+trap "atexit" EXIT
+failures=0
+
+function compile_module()
+{
+	local android_mk="$1"
+
+	echo "Compiling .${android_mk:${#PWD}}"
+	ONE_SHOT_MAKEFILE="$android_mk" make -C "../../../../../" files | tee -a $log
+	if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
+		exit 1
+	fi
+}
+
+function wait_for_boot_completed()
+{
+	echo "Rebooting device"
+	$adb wait-for-device logcat -c
+	$adb wait-for-device logcat | grep -m 1 -e 'PowerManagerService.*bootCompleted' >/dev/null
+}
+
+function disable_overlay()
+{
+	echo "Disabling overlay"
+	$adb shell rm /vendor/overlay/framework/framework-res.apk
+	$adb shell rm /data/resource-cache/vendor@overlay@framework@framework-res.apk@idmap
+}
+
+function enable_overlay()
+{
+	echo "Enabling overlay"
+	$adb shell ln -s /data/app/com.android.overlaytest.overlay.apk /vendor/overlay/framework/framework-res.apk
+}
+
+function instrument()
+{
+	local class="$1"
+
+	echo "Instrumenting $class"
+	$adb shell am instrument -w -e class $class com.android.overlaytest/android.test.InstrumentationTestRunner | tee -a $log
+}
+
+function sync()
+{
+	echo "Syncing to device"
+	$adb remount | tee -a $log
+	$adb sync data | tee -a $log
+}
+
+# build and sync
+compile_module "$PWD/OverlayTest/Android.mk"
+compile_module "$PWD/OverlayTestOverlay/Android.mk"
+sync
+
+# instrument test (without overlay)
+$adb shell stop
+disable_overlay
+$adb shell start
+wait_for_boot_completed
+instrument "com.android.overlaytest.WithoutOverlayTest"
+
+# instrument test (with overlay)
+$adb shell stop
+enable_overlay
+$adb shell start
+wait_for_boot_completed
+instrument "com.android.overlaytest.WithOverlayTest"
+
+# cleanup
+exit $(grep -c -e '^FAILURES' $log)
diff --git a/data/fonts/MTLc3m.ttf b/data/fonts/MTLc3m.ttf
index 3cc5c96..86bdcc7 100644
--- a/data/fonts/MTLc3m.ttf
+++ b/data/fonts/MTLc3m.ttf
Binary files differ
diff --git a/data/fonts/MTLmr3m.ttf b/data/fonts/MTLmr3m.ttf
index 05b9093..76fe737 100644
--- a/data/fonts/MTLmr3m.ttf
+++ b/data/fonts/MTLmr3m.ttf
Binary files differ
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 12dc93c..40d54bb 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -681,7 +681,8 @@
      */
     public enum CompressFormat {
         JPEG    (0),
-        PNG     (1);
+        PNG     (1),
+        WEBP    (2);
 
         CompressFormat(int nativeInt) {
             this.nativeInt = nativeInt;
diff --git a/graphics/java/android/graphics/Movie.java b/graphics/java/android/graphics/Movie.java
index 95e9946..4a33453 100644
--- a/graphics/java/android/graphics/Movie.java
+++ b/graphics/java/android/graphics/Movie.java
@@ -46,6 +46,8 @@
     public static native Movie decodeByteArray(byte[] data, int offset,
                                                int length);
 
+    private static native void nativeDestructor(int nativeMovie);
+
     public static Movie decodeFile(String pathName) {
         InputStream is;
         try {
@@ -57,6 +59,15 @@
         return decodeTempStream(is);
     }
 
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            nativeDestructor(mNativeMovie);
+        } finally {
+            super.finalize();
+        }
+    }
+
     private static Movie decodeTempStream(InputStream is) {
         Movie moov = null;
         try {
diff --git a/graphics/java/android/graphics/YuvImage.java b/graphics/java/android/graphics/YuvImage.java
index 9368da6..af3f276 100644
--- a/graphics/java/android/graphics/YuvImage.java
+++ b/graphics/java/android/graphics/YuvImage.java
@@ -36,7 +36,7 @@
     private final static int WORKING_COMPRESS_STORAGE = 4096;
 
    /**
-     * The YUV format as defined in {@link PixelFormat}.
+     * The YUV format as defined in {@link ImageFormat}.
      */
     private int mFormat;
 
@@ -67,7 +67,7 @@
      *
      * @param yuv     The YUV data. In the case of more than one image plane, all the planes must be
      *                concatenated into a single byte array.
-     * @param format  The YUV data format as defined in {@link PixelFormat}.
+     * @param format  The YUV data format as defined in {@link ImageFormat}.
      * @param width   The width of the YuvImage.
      * @param height  The height of the YuvImage.
      * @param strides (Optional) Row bytes of each image plane. If yuv contains padding, the stride
@@ -152,7 +152,7 @@
     }
 
     /**
-     * @return the YUV format as defined in {@link PixelFormat}.
+     * @return the YUV format as defined in {@link ImageFormat}.
      */
     public int getYuvFormat() {
         return mFormat;
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index 2c09ddc..6e62ab3 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -486,10 +486,8 @@
         mBitmapState = state;
         if (res != null) {
             mTargetDensity = res.getDisplayMetrics().densityDpi;
-        } else if (state != null) {
-            mTargetDensity = state.mTargetDensity;
         } else {
-            mTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
+            mTargetDensity = state.mTargetDensity;
         }
         setBitmap(state.mBitmap);
     }
diff --git a/include/media/EffectApi.h b/include/media/EffectApi.h
index b97c22e..6e6660c 100644
--- a/include/media/EffectApi.h
+++ b/include/media/EffectApi.h
@@ -602,9 +602,9 @@
 
 // Audio mode
 enum audio_mode_e {
-    AUDIO_MODE_NORMAL,      // device idle
-    AUDIO_MODE_RINGTONE,    // device ringing
-    AUDIO_MODE_IN_CALL      // audio call connected (VoIP or telephony)
+    AUDIO_EFFECT_MODE_NORMAL,   // device idle
+    AUDIO_EFFECT_MODE_RINGTONE, // device ringing
+    AUDIO_EFFECT_MODE_IN_CALL   // audio call connected (VoIP or telephony)
 };
 
 // Values for "accessMode" field of buffer_config_t:
diff --git a/include/utils/AssetManager.h b/include/utils/AssetManager.h
index 9e2bf37..a8c7ddb 100644
--- a/include/utils/AssetManager.h
+++ b/include/utils/AssetManager.h
@@ -222,6 +222,7 @@
     {
         String8 path;
         FileType type;
+        String8 idmap;
     };
 
     Asset* openInPathLocked(const char* fileName, AccessMode mode,
@@ -262,6 +263,16 @@
     void setLocaleLocked(const char* locale);
     void updateResourceParamsLocked() const;
 
+    bool createIdmapFileLocked(const String8& originalPath, const String8& overlayPath,
+                               const String8& idmapPath);
+
+    bool isIdmapStaleLocked(const String8& originalPath, const String8& overlayPath,
+                            const String8& idmapPath);
+
+    Asset* openIdmapLocked(const struct asset_path& ap) const;
+
+    bool getZipEntryCrcLocked(const String8& zipPath, const char* entryFilename, uint32_t* pCrc);
+
     class SharedZip : public RefBase {
     public:
         static sp<SharedZip> get(const String8& path);
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index 0603ed5..612ff93 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -1813,9 +1813,9 @@
     ~ResTable();
 
     status_t add(const void* data, size_t size, void* cookie,
-                 bool copyData=false);
+                 bool copyData=false, const void* idmap = NULL);
     status_t add(Asset* asset, void* cookie,
-                 bool copyData=false);
+                 bool copyData=false, const void* idmap = NULL);
     status_t add(ResTable* src);
 
     status_t getError() const;
@@ -2062,6 +2062,24 @@
 
     void getLocales(Vector<String8>* locales) const;
 
+    // Generate an idmap.
+    //
+    // Return value: on success: NO_ERROR; caller is responsible for free-ing
+    // outData (using free(3)). On failure, any status_t value other than
+    // NO_ERROR; the caller should not free outData.
+    status_t createIdmap(const ResTable& overlay, uint32_t originalCrc, uint32_t overlayCrc,
+                         void** outData, size_t* outSize) const;
+
+    enum {
+        IDMAP_HEADER_SIZE_BYTES = 3 * sizeof(uint32_t),
+    };
+    // Retrieve idmap meta-data.
+    //
+    // This function only requires the idmap header (the first
+    // IDMAP_HEADER_SIZE_BYTES) bytes of an idmap file.
+    static bool getIdmapInfo(const void* idmap, size_t size,
+                             uint32_t* pOriginalCrc, uint32_t* pOverlayCrc);
+
 #ifndef HAVE_ANDROID_OS
     void print(bool inclValues) const;
     static String8 normalizeForOutput(const char* input);
@@ -2075,7 +2093,7 @@
     struct bag_set;
 
     status_t add(const void* data, size_t size, void* cookie,
-                 Asset* asset, bool copyData);
+                 Asset* asset, bool copyData, const Asset* idmap);
 
     ssize_t getResourcePackageIndex(uint32_t resID) const;
     ssize_t getEntry(
@@ -2084,7 +2102,7 @@
         const ResTable_type** outType, const ResTable_entry** outEntry,
         const Type** outTypeClass) const;
     status_t parsePackage(
-        const ResTable_package* const pkg, const Header* const header);
+        const ResTable_package* const pkg, const Header* const header, uint32_t idmap_id);
 
     void print_value(const Package* pkg, const Res_value& value) const;
     
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index d9d7d231..3f253b0 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2004,12 +2004,11 @@
 }
 
 SkXfermode::Mode OpenGLRenderer::getXfermode(SkXfermode* mode) {
-    // In the future we should look at unifying the Porter-Duff modes and
-    // SkXferModes so that we can use SkXfermode::IsMode(xfer, &mode).
-    if (mode == NULL) {
-        return SkXfermode::kSrcOver_Mode;
+    SkXfermode::Mode resultMode;
+    if (!SkXfermode::AsMode(mode, &resultMode)) {
+        resultMode = SkXfermode::kSrcOver_Mode;
     }
-    return mode->fMode;
+    return resultMode;
 }
 
 void OpenGLRenderer::setTextureWrapModes(Texture* texture, GLenum wrapS, GLenum wrapT) {
diff --git a/libs/usb/src/com/android/future/usb/UsbManager.java b/libs/usb/src/com/android/future/usb/UsbManager.java
index d424b63..91d8e8a 100644
--- a/libs/usb/src/com/android/future/usb/UsbManager.java
+++ b/libs/usb/src/com/android/future/usb/UsbManager.java
@@ -28,7 +28,7 @@
 import android.util.Log;
 
 /**
- * This class allows you to access the state of USB, both in host and device mode.
+ * This is a wrapper class for the USB Manager to support USB accessories.
  *
  * <p>You can obtain an instance of this class by calling {@link #getInstance}
  *
@@ -141,7 +141,7 @@
     /**
      * Returns true if the caller has permission to access the accessory.
      * Permission might have been granted temporarily via
-     * {@link #requestPermission(android.hardware.usb.UsbAccessory} or
+     * {@link #requestPermission} or
      * by the user choosing the caller as the default application for the accessory.
      *
      * @param accessory to check permissions for
diff --git a/libs/utils/AssetManager.cpp b/libs/utils/AssetManager.cpp
index e09e755..0b4d1ac 100644
--- a/libs/utils/AssetManager.cpp
+++ b/libs/utils/AssetManager.cpp
@@ -36,6 +36,19 @@
 #include <dirent.h>
 #include <errno.h>
 #include <assert.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifndef TEMP_FAILURE_RETRY
+/* Used to retry syscalls that can return EINTR. */
+#define TEMP_FAILURE_RETRY(exp) ({         \
+    typeof (exp) _rc;                      \
+    do {                                   \
+        _rc = (exp);                       \
+    } while (_rc == -1 && errno == EINTR); \
+    _rc; })
+#endif
 
 using namespace android;
 
@@ -48,6 +61,7 @@
 static const char* kAssetsRoot = "assets";
 static const char* kAppZipName = NULL; //"classes.jar";
 static const char* kSystemAssets = "framework/framework-res.apk";
+static const char* kIdmapCacheDir = "resource-cache";
 
 static const char* kExcludeExtension = ".EXCLUDE";
 
@@ -55,6 +69,35 @@
 
 static volatile int32_t gCount = 0;
 
+namespace {
+    // Transform string /a/b/c.apk to /data/resource-cache/a@b@c.apk@idmap
+    String8 idmapPathForPackagePath(const String8& pkgPath)
+    {
+        const char* root = getenv("ANDROID_DATA");
+        LOG_ALWAYS_FATAL_IF(root == NULL, "ANDROID_DATA not set");
+        String8 path(root);
+        path.appendPath(kIdmapCacheDir);
+
+        char buf[256]; // 256 chars should be enough for anyone...
+        strncpy(buf, pkgPath.string(), 255);
+        buf[255] = '\0';
+        char* filename = buf;
+        while (*filename && *filename == '/') {
+            ++filename;
+        }
+        char* p = filename;
+        while (*p) {
+            if (*p == '/') {
+                *p = '@';
+            }
+            ++p;
+        }
+        path.appendPath(filename);
+        path.append("@idmap");
+
+        return path;
+    }
+}
 
 /*
  * ===========================================================================
@@ -122,7 +165,7 @@
             return true;
         }
     }
-    
+
     LOGV("In %p Asset %s path: %s", this,
          ap.type == kFileTypeDirectory ? "dir" : "zip", ap.path.string());
 
@@ -133,9 +176,181 @@
         *cookie = (void*)mAssetPaths.size();
     }
 
+    // add overlay packages for /system/framework; apps are handled by the
+    // (Java) package manager
+    if (strncmp(path.string(), "/system/framework/", 18) == 0) {
+        // When there is an environment variable for /vendor, this
+        // should be changed to something similar to how ANDROID_ROOT
+        // and ANDROID_DATA are used in this file.
+        String8 overlayPath("/vendor/overlay/framework/");
+        overlayPath.append(path.getPathLeaf());
+        if (TEMP_FAILURE_RETRY(access(overlayPath.string(), R_OK)) == 0) {
+            asset_path oap;
+            oap.path = overlayPath;
+            oap.type = ::getFileType(overlayPath.string());
+            bool addOverlay = (oap.type == kFileTypeRegular); // only .apks supported as overlay
+            if (addOverlay) {
+                oap.idmap = idmapPathForPackagePath(overlayPath);
+
+                if (isIdmapStaleLocked(ap.path, oap.path, oap.idmap)) {
+                    addOverlay = createIdmapFileLocked(ap.path, oap.path, oap.idmap);
+                }
+            }
+            if (addOverlay) {
+                mAssetPaths.add(oap);
+            } else {
+                LOGW("failed to add overlay package %s\n", overlayPath.string());
+            }
+        }
+    }
+
     return true;
 }
 
+bool AssetManager::isIdmapStaleLocked(const String8& originalPath, const String8& overlayPath,
+                                      const String8& idmapPath)
+{
+    struct stat st;
+    if (TEMP_FAILURE_RETRY(stat(idmapPath.string(), &st)) == -1) {
+        if (errno == ENOENT) {
+            return true; // non-existing idmap is always stale
+        } else {
+            LOGW("failed to stat file %s: %s\n", idmapPath.string(), strerror(errno));
+            return false;
+        }
+    }
+    if (st.st_size < ResTable::IDMAP_HEADER_SIZE_BYTES) {
+        LOGW("file %s has unexpectedly small size=%zd\n", idmapPath.string(), (size_t)st.st_size);
+        return false;
+    }
+    int fd = TEMP_FAILURE_RETRY(::open(idmapPath.string(), O_RDONLY));
+    if (fd == -1) {
+        LOGW("failed to open file %s: %s\n", idmapPath.string(), strerror(errno));
+        return false;
+    }
+    char buf[ResTable::IDMAP_HEADER_SIZE_BYTES];
+    ssize_t bytesLeft = ResTable::IDMAP_HEADER_SIZE_BYTES;
+    for (;;) {
+        ssize_t r = TEMP_FAILURE_RETRY(read(fd, buf + ResTable::IDMAP_HEADER_SIZE_BYTES - bytesLeft,
+                                            bytesLeft));
+        if (r < 0) {
+            TEMP_FAILURE_RETRY(close(fd));
+            return false;
+        }
+        bytesLeft -= r;
+        if (bytesLeft == 0) {
+            break;
+        }
+    }
+    TEMP_FAILURE_RETRY(close(fd));
+
+    uint32_t cachedOriginalCrc, cachedOverlayCrc;
+    if (!ResTable::getIdmapInfo(buf, ResTable::IDMAP_HEADER_SIZE_BYTES,
+                                &cachedOriginalCrc, &cachedOverlayCrc)) {
+        return false;
+    }
+
+    uint32_t actualOriginalCrc, actualOverlayCrc;
+    if (!getZipEntryCrcLocked(originalPath, "resources.arsc", &actualOriginalCrc)) {
+        return false;
+    }
+    if (!getZipEntryCrcLocked(overlayPath, "resources.arsc", &actualOverlayCrc)) {
+        return false;
+    }
+    return cachedOriginalCrc != actualOriginalCrc || cachedOverlayCrc != actualOverlayCrc;
+}
+
+bool AssetManager::getZipEntryCrcLocked(const String8& zipPath, const char* entryFilename,
+                                        uint32_t* pCrc)
+{
+    asset_path ap;
+    ap.path = zipPath;
+    const ZipFileRO* zip = getZipFileLocked(ap);
+    if (zip == NULL) {
+        return false;
+    }
+    const ZipEntryRO entry = zip->findEntryByName(entryFilename);
+    if (entry == NULL) {
+        return false;
+    }
+    if (!zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)pCrc)) {
+        return false;
+    }
+    return true;
+}
+
+bool AssetManager::createIdmapFileLocked(const String8& originalPath, const String8& overlayPath,
+                                         const String8& idmapPath)
+{
+    LOGD("%s: originalPath=%s overlayPath=%s idmapPath=%s\n",
+         __FUNCTION__, originalPath.string(), overlayPath.string(), idmapPath.string());
+    ResTable tables[2];
+    const String8* paths[2] = { &originalPath, &overlayPath };
+    uint32_t originalCrc, overlayCrc;
+    bool retval = false;
+    ssize_t offset = 0;
+    int fd = 0;
+    uint32_t* data = NULL;
+    size_t size;
+
+    for (int i = 0; i < 2; ++i) {
+        asset_path ap;
+        ap.type = kFileTypeRegular;
+        ap.path = *paths[i];
+        Asset* ass = openNonAssetInPathLocked("resources.arsc", Asset::ACCESS_BUFFER, ap);
+        if (ass == NULL) {
+            LOGW("failed to find resources.arsc in %s\n", ap.path.string());
+            goto error;
+        }
+        tables[i].add(ass, (void*)1, false);
+    }
+
+    if (!getZipEntryCrcLocked(originalPath, "resources.arsc", &originalCrc)) {
+        LOGW("failed to retrieve crc for resources.arsc in %s\n", originalPath.string());
+        goto error;
+    }
+    if (!getZipEntryCrcLocked(overlayPath, "resources.arsc", &overlayCrc)) {
+        LOGW("failed to retrieve crc for resources.arsc in %s\n", overlayPath.string());
+        goto error;
+    }
+
+    if (tables[0].createIdmap(tables[1], originalCrc, overlayCrc,
+                              (void**)&data, &size) != NO_ERROR) {
+        LOGW("failed to generate idmap data for file %s\n", idmapPath.string());
+        goto error;
+    }
+
+    // This should be abstracted (eg replaced by a stand-alone
+    // application like dexopt, triggered by something equivalent to
+    // installd).
+    fd = TEMP_FAILURE_RETRY(::open(idmapPath.string(), O_WRONLY | O_CREAT | O_TRUNC, 0644));
+    if (fd == -1) {
+        LOGW("failed to write idmap file %s (open: %s)\n", idmapPath.string(), strerror(errno));
+        goto error_free;
+    }
+    for (;;) {
+        ssize_t written = TEMP_FAILURE_RETRY(write(fd, data + offset, size));
+        if (written < 0) {
+            LOGW("failed to write idmap file %s (write: %s)\n", idmapPath.string(),
+                 strerror(errno));
+            goto error_close;
+        }
+        size -= (size_t)written;
+        offset += written;
+        if (size == 0) {
+            break;
+        }
+    }
+
+    retval = true;
+error_close:
+    TEMP_FAILURE_RETRY(close(fd));
+error_free:
+    free(data);
+error:
+    return retval;
+}
+
 bool AssetManager::addDefaultAssets()
 {
     const char* root = getenv("ANDROID_ROOT");
@@ -404,6 +619,7 @@
         ResTable* sharedRes = NULL;
         bool shared = true;
         const asset_path& ap = mAssetPaths.itemAt(i);
+        Asset* idmap = openIdmapLocked(ap);
         LOGV("Looking for resource asset in '%s'\n", ap.path.string());
         if (ap.type != kFileTypeDirectory) {
             if (i == 0) {
@@ -433,7 +649,7 @@
                     // can quickly copy it out for others.
                     LOGV("Creating shared resources for %s", ap.path.string());
                     sharedRes = new ResTable();
-                    sharedRes->add(ass, (void*)(i+1), false);
+                    sharedRes->add(ass, (void*)(i+1), false, idmap);
                     sharedRes = const_cast<AssetManager*>(this)->
                         mZipSet.setZipResourceTable(ap.path, sharedRes);
                 }
@@ -457,13 +673,16 @@
                 rt->add(sharedRes);
             } else {
                 LOGV("Parsing resources for %s", ap.path.string());
-                rt->add(ass, (void*)(i+1), !shared);
+                rt->add(ass, (void*)(i+1), !shared, idmap);
             }
 
             if (!shared) {
                 delete ass;
             }
         }
+        if (idmap != NULL) {
+            delete idmap;
+        }
     }
 
     if (required && !rt) LOGW("Unable to find resources file resources.arsc");
@@ -498,6 +717,21 @@
     res->setParameters(mConfig);
 }
 
+Asset* AssetManager::openIdmapLocked(const struct asset_path& ap) const
+{
+    Asset* ass = NULL;
+    if (ap.idmap.size() != 0) {
+        ass = const_cast<AssetManager*>(this)->
+            openAssetFromFileLocked(ap.idmap, Asset::ACCESS_BUFFER);
+        if (ass) {
+            LOGV("loading idmap %s\n", ap.idmap.string());
+        } else {
+            LOGW("failed to load idmap %s\n", ap.idmap.string());
+        }
+    }
+    return ass;
+}
+
 const ResTable& AssetManager::getResources(bool required) const
 {
     const ResTable* rt = getResTable(required);
diff --git a/libs/utils/README b/libs/utils/README
index 36a706d..01741e0 100644
--- a/libs/utils/README
+++ b/libs/utils/README
@@ -1,4 +1,6 @@
 Android Utility Function Library
+================================
+
 
 If you need a feature that is native to Linux but not present on other
 platforms, construct a platform-dependent implementation that shares
@@ -12,3 +14,276 @@
 layer.  The goal is to provide an optimized solution for Linux with
 reasonable implementations for other platforms.
 
+
+
+Resource overlay
+================
+
+
+Introduction
+------------
+
+Overlay packages are special .apk files which provide no code but
+additional resource values (and possibly new configurations) for
+resources in other packages. When an application requests resources,
+the system will return values from either the application's original
+package or any associated overlay package. Any redirection is completely
+transparent to the calling application.
+
+Resource values have the following precedence table, listed in
+descending precedence.
+
+ * overlay package, matching config (eg res/values-en-land)
+
+ * original package, matching config
+
+ * overlay package, no config (eg res/values)
+
+ * original package, no config
+
+During compilation, overlay packages are differentiated from regular
+packages by passing the -o flag to aapt.
+
+
+Background
+----------
+
+This section provides generic background material on resources in
+Android.
+
+
+How resources are bundled in .apk files
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Android .apk files are .zip files, usually housing .dex code,
+certificates and resources, though packages containing resources but
+no code are possible. Resources can be divided into the following
+categories; a `configuration' indicates a set of phone language, display
+density, network operator, etc.
+
+ * assets: uncompressed, raw files packaged as part of an .apk and
+           explicitly referenced by filename. These files are
+           independent of configuration.
+
+ * res/drawable: bitmap or xml graphics. Each file may have different
+                 values depending on configuration.
+
+ * res/values: integers, strings, etc. Each resource may have different
+               values depending on configuration.
+
+Resource meta information and information proper is stored in a binary
+format in a named file resources.arsc, bundled as part of the .apk.
+
+Resource IDs and lookup
+~~~~~~~~~~~~~~~~~~~~~~~
+During compilation, the aapt tool gathers application resources and
+generates a resources.arsc file. Each resource name is assigned an
+integer ID 0xppttiii (translated to a symbolic name via R.java), where
+
+ * pp: corresponds to the package namespace (details below).
+
+ * tt: corresponds to the resource type (string, int, etc). Every
+       resource of the same type within the same package has the same
+       tt value, but depending on available types, the actual numerical
+       value may be different between packages.
+
+ * iiii: sequential number, assigned in the order resources are found.
+
+Resource values are specified paired with a set of configuration
+constraints (the default being the empty set), eg res/values-sv-port
+which imposes restrictions on language (Swedish) and display orientation
+(portrait). During lookup, every constraint set is matched against the
+current configuration, and the value corresponding to the best matching
+constraint set is returned (ResourceTypes.{h,cpp}).
+
+Parsing of resources.arsc is handled by ResourceTypes.cpp; this utility
+is governed by AssetManager.cpp, which tracks loaded resources per
+process.
+
+Assets are looked up by path and filename in AssetManager.cpp. The path
+to resources in res/drawable are located by ResourceTypes.cpp and then
+handled like assets by AssetManager.cpp. Other resources are handled
+solely by ResourceTypes.cpp.
+
+Package ID as namespace
+~~~~~~~~~~~~~~~~~~~~~~~
+The pp part of a resource ID defines a namespace. Android currently
+defines two namespaces:
+
+ * 0x01: system resources (pre-installed in framework-res.apk)
+
+ * 0x7f: application resources (bundled in the application .apk)
+
+ResourceTypes.cpp supports package IDs between 0x01 and 0x7f
+(inclusive); values outside this range are invalid.
+
+Each running (Dalvik) process is assigned a unique instance of
+AssetManager, which in turn keeps a forest structure of loaded
+resource.arsc files. Normally, this forest is structured as follows,
+where mPackageMap is the internal vector employed in ResourceTypes.cpp.
+
+mPackageMap[0x00] -> system package
+mPackageMap[0x01] -> NULL
+mPackageMap[0x02] -> NULL
+...
+mPackageMap[0x7f - 2] -> NULL
+mPackageMap[0x7f - 1] -> application package
+
+
+
+The resource overlay extension
+------------------------------
+
+The resource overlay mechanism aims to (partly) shadow and extend
+existing resources with new values for defined and new configurations.
+Technically, this is achieved by adding resource-only packages (called
+overlay packages) to existing resource namespaces, like so:
+
+mPackageMap[0x00] -> system package -> system overlay package
+mPackageMap[0x01] -> NULL
+mPackageMap[0x02] -> NULL
+...
+mPackageMap[0x7f - 2] -> NULL
+mPackageMap[0x7f - 1] -> application package -> overlay 1 -> overlay 2
+
+The use of overlay resources is completely transparent to
+applications; no additional resource identifiers are introduced, only
+configuration/value pairs. Any number of overlay packages may be loaded
+at a time; overlay packages are agnostic to what they target -- both
+system and application resources are fair game.
+
+The package targeted by an overlay package is called the target or
+original package.
+
+Resource overlay operates on symbolic resources names. Hence, to
+override the string/str1 resources in a package, the overlay package
+would include a resource also named string/str1. The end user does not
+have to worry about the numeric resources IDs assigned by aapt, as this
+is resolved automatically by the system.
+
+As of this writing, the use of resource overlay has not been fully
+explored. Until it has, only OEMs are trusted to use resource overlay.
+For this reason, overlay packages must reside in /system/overlay.
+
+
+Resource ID mapping
+~~~~~~~~~~~~~~~~~~~
+Resource identifiers must be coherent within the same namespace (ie
+PackageGroup in ResourceTypes.cpp). Calling applications will refer to
+resources using the IDs defined in the original package, but there is no
+guarantee aapt has assigned the same ID to the corresponding resource in
+an overlay package. To translate between the two, a resource ID mapping
+{original ID -> overlay ID} is created during package installation
+(PackageManagerService.java) and used during resource lookup. The
+mapping is stored in /data/resource-cache, with a @idmap file name
+suffix.
+
+The idmap file format is documented in a separate section, below.
+
+
+Package management
+~~~~~~~~~~~~~~~~~~
+Packages are managed by the PackageManagerService. Addition and removal
+of packages are monitored via the inotify framework, exposed via
+android.os.FileObserver.
+
+During initialization of a Dalvik process, ActivityThread.java requests
+the process' AssetManager (by proxy, via AssetManager.java and JNI)
+to load a list of packages. This list includes overlay packages, if
+present.
+
+When a target package or a corresponding overlay package is installed,
+the target package's process is stopped and a new idmap is generated.
+This is similar to how applications are stopped when their packages are
+upgraded.
+
+
+Creating overlay packages
+-------------------------
+
+Overlay packages should contain no code, define (some) resources with
+the same type and name as in the original package, and be compiled with
+the -o flag passed to aapt.
+
+The aapt -o flag instructs aapt to create an overlay package.
+Technically, this means the package will be assigned package id 0x00.
+
+There are no restrictions on overlay packages names, though the naming
+convention <original.package.name>.overlay.<name> is recommended.
+
+
+Example overlay package
+~~~~~~~~~~~~~~~~~~~~~~~
+
+To overlay the resource bool/b in package com.foo.bar, to be applied
+when the display is in landscape mode, create a new package with
+no source code and a single .xml file under res/values-land, with
+an entry for bool/b. Compile with aapt -o and place the results in
+/system/overlay by adding the following to Android.mk:
+
+LOCAL_AAPT_FLAGS := -o com.foo.bar
+LOCAL_MODULE_PATH := $(TARGET_OUT)/overlay
+
+
+The ID map (idmap) file format
+------------------------------
+
+The idmap format is designed for lookup performance. However, leading
+and trailing undefined overlay values are discarded to reduce the memory
+footprint.
+
+
+idmap grammar
+~~~~~~~~~~~~~
+All atoms (names in square brackets) are uint32_t integers. The
+idmap-magic constant spells "idmp" in ASCII. Offsets are given relative
+to the data_header, not to the beginning of the file.
+
+map          := header data
+header       := idmap-magic <crc32-original-pkg> <crc32-overlay-pkg>
+idmap-magic  := <0x706d6469>
+data         := data_header type_block+
+data_header  := <m> header_block{m}
+header_block := <0> | <type_block_offset>
+type_block   := <n> <id_offset> entry{n}
+entry        := <resource_id_in_target_package>
+
+
+idmap example
+~~~~~~~~~~~~~
+Given a pair of target and overlay packages with CRC sums 0x216a8fe2
+and 0x6b9beaec, each defining the following resources
+
+Name          Target package  Overlay package
+string/str0   0x7f010000      -
+string/str1   0x7f010001      0x7f010000
+string/str2   0x7f010002      -
+string/str3   0x7f010003      0x7f010001
+string/str4   0x7f010004      -
+bool/bool0    0x7f020000      -
+integer/int0  0x7f030000      0x7f020000
+integer/int1  0x7f030001      -
+
+the corresponding resource map is
+
+0x706d6469 0x216a8fe2 0x6b9beaec 0x00000003 \
+0x00000004 0x00000000 0x00000009 0x00000003 \
+0x00000001 0x7f010000 0x00000000 0x7f010001 \
+0x00000001 0x00000000 0x7f020000
+
+or, formatted differently
+
+0x706d6469  # magic: all idmap files begin with this constant
+0x216a8fe2  # CRC32 of the resources.arsc file in the original package
+0x6b9beaec  # CRC32 of the resources.arsc file in the overlay package
+0x00000003  # header; three types (string, bool, integer) in the target package
+0x00000004  #   header_block for type 0 (string) is located at offset 4
+0x00000000  #   no bool type exists in overlay package -> no header_block
+0x00000009  #   header_block for type 2 (integer) is located at offset 9
+0x00000003  # header_block for string; overlay IDs span 3 elements
+0x00000001  #   the first string in target package is entry 1 == offset
+0x7f010000  #   target 0x7f01001 -> overlay 0x7f010000
+0x00000000  #   str2 not defined in overlay package
+0x7f010001  #   target 0x7f010003 -> overlay 0x7f010001
+0x00000001  # header_block for integer; overlay IDs span 1 element
+0x00000000  #   offset == 0
+0x7f020000  #   target 0x7f030000 -> overlay 0x7f020000
diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp
index bb6c125..2034486 100644
--- a/libs/utils/RefBase.cpp
+++ b/libs/utils/RefBase.cpp
@@ -524,7 +524,7 @@
 
 void RefBase::weakref_type::trackMe(bool enable, bool retain)
 {
-    static_cast<const weakref_impl*>(this)->trackMe(enable, retain);
+    static_cast<weakref_impl*>(this)->trackMe(enable, retain);
 }
 
 RefBase::weakref_type* RefBase::createWeak(const void* id) const
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index ecb8c0c..cb6c246 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -63,6 +63,10 @@
 #endif
 #endif
 
+#define IDMAP_MAGIC         0x706d6469
+// size measured in sizeof(uint32_t)
+#define IDMAP_HEADER_SIZE (ResTable::IDMAP_HEADER_SIZE_BYTES / sizeof(uint32_t))
+
 static void printToLogFunc(void* cookie, const char* txt)
 {
     LOGV("%s", txt);
@@ -214,6 +218,81 @@
     outData->colors = (uint32_t*) data;
 }
 
+static bool assertIdmapHeader(const uint32_t* map, size_t sizeBytes)
+{
+    if (sizeBytes < ResTable::IDMAP_HEADER_SIZE_BYTES) {
+        LOGW("idmap assertion failed: size=%d bytes\n", sizeBytes);
+        return false;
+    }
+    if (*map != htodl(IDMAP_MAGIC)) { // htodl: map data expected to be in correct endianess
+        LOGW("idmap assertion failed: invalid magic found (is 0x%08x, expected 0x%08x)\n",
+             *map, htodl(IDMAP_MAGIC));
+        return false;
+    }
+    return true;
+}
+
+static status_t idmapLookup(const uint32_t* map, size_t sizeBytes, uint32_t key, uint32_t* outValue)
+{
+    // see README for details on the format of map
+    if (!assertIdmapHeader(map, sizeBytes)) {
+        return UNKNOWN_ERROR;
+    }
+    map = map + IDMAP_HEADER_SIZE; // skip ahead to data segment
+    // size of data block, in uint32_t
+    const size_t size = (sizeBytes - ResTable::IDMAP_HEADER_SIZE_BYTES) / sizeof(uint32_t);
+    const uint32_t type = Res_GETTYPE(key) + 1; // add one, idmap stores "public" type id
+    const uint32_t entry = Res_GETENTRY(key);
+    const uint32_t typeCount = *map;
+
+    if (type > typeCount) {
+        LOGW("Resource ID map: type=%d exceeds number of types=%d\n", type, typeCount);
+        return UNKNOWN_ERROR;
+    }
+    if (typeCount > size) {
+        LOGW("Resource ID map: number of types=%d exceeds size of map=%d\n", typeCount, size);
+        return UNKNOWN_ERROR;
+    }
+    const uint32_t typeOffset = map[type];
+    if (typeOffset == 0) {
+        *outValue = 0;
+        return NO_ERROR;
+    }
+    if (typeOffset + 1 > size) {
+        LOGW("Resource ID map: type offset=%d exceeds reasonable value, size of map=%d\n",
+             typeOffset, size);
+        return UNKNOWN_ERROR;
+    }
+    const uint32_t entryCount = map[typeOffset];
+    const uint32_t entryOffset = map[typeOffset + 1];
+    if (entryCount == 0 || entry < entryOffset || entry - entryOffset > entryCount - 1) {
+        *outValue = 0;
+        return NO_ERROR;
+    }
+    const uint32_t index = typeOffset + 2 + entry - entryOffset;
+    if (index > size) {
+        LOGW("Resource ID map: entry index=%d exceeds size of map=%d\n", index, size);
+        *outValue = 0;
+        return NO_ERROR;
+    }
+    *outValue = map[index];
+
+    return NO_ERROR;
+}
+
+static status_t getIdmapPackageId(const uint32_t* map, size_t mapSize, uint32_t *outId)
+{
+    if (!assertIdmapHeader(map, mapSize)) {
+        return UNKNOWN_ERROR;
+    }
+    const uint32_t* p = map + IDMAP_HEADER_SIZE + 1;
+    while (*p == 0) {
+        ++p;
+    }
+    *outId = (map[*p + IDMAP_HEADER_SIZE + 2] >> 24) & 0x000000ff;
+    return NO_ERROR;
+}
+
 Res_png_9patch* Res_png_9patch::deserialize(const void* inData)
 {
     if (sizeof(void*) != sizeof(int32_t)) {
@@ -1290,7 +1369,13 @@
 
 struct ResTable::Header
 {
-    Header(ResTable* _owner) : owner(_owner), ownedData(NULL), header(NULL) { }
+    Header(ResTable* _owner) : owner(_owner), ownedData(NULL), header(NULL),
+        resourceIDMap(NULL), resourceIDMapSize(0) { }
+
+    ~Header()
+    {
+        free(resourceIDMap);
+    }
 
     ResTable* const                 owner;
     void*                           ownedData;
@@ -1301,6 +1386,8 @@
     void*                           cookie;
 
     ResStringPool                   values;
+    uint32_t*                       resourceIDMap;
+    size_t                          resourceIDMapSize;
 };
 
 struct ResTable::Type
@@ -1716,12 +1803,13 @@
     return ((ssize_t)mPackageMap[Res_GETPACKAGE(resID)+1])-1;
 }
 
-status_t ResTable::add(const void* data, size_t size, void* cookie, bool copyData)
+status_t ResTable::add(const void* data, size_t size, void* cookie, bool copyData,
+                       const void* idmap)
 {
-    return add(data, size, cookie, NULL, copyData);
+    return add(data, size, cookie, NULL, copyData, reinterpret_cast<const Asset*>(idmap));
 }
 
-status_t ResTable::add(Asset* asset, void* cookie, bool copyData)
+status_t ResTable::add(Asset* asset, void* cookie, bool copyData, const void* idmap)
 {
     const void* data = asset->getBuffer(true);
     if (data == NULL) {
@@ -1729,7 +1817,7 @@
         return UNKNOWN_ERROR;
     }
     size_t size = (size_t)asset->getLength();
-    return add(data, size, cookie, asset, copyData);
+    return add(data, size, cookie, asset, copyData, reinterpret_cast<const Asset*>(idmap));
 }
 
 status_t ResTable::add(ResTable* src)
@@ -1757,19 +1845,30 @@
 }
 
 status_t ResTable::add(const void* data, size_t size, void* cookie,
-                       Asset* asset, bool copyData)
+                       Asset* asset, bool copyData, const Asset* idmap)
 {
     if (!data) return NO_ERROR;
     Header* header = new Header(this);
     header->index = mHeaders.size();
     header->cookie = cookie;
+    if (idmap != NULL) {
+        const size_t idmap_size = idmap->getLength();
+        const void* idmap_data = const_cast<Asset*>(idmap)->getBuffer(true);
+        header->resourceIDMap = (uint32_t*)malloc(idmap_size);
+        if (header->resourceIDMap == NULL) {
+            delete header;
+            return (mError = NO_MEMORY);
+        }
+        memcpy((void*)header->resourceIDMap, idmap_data, idmap_size);
+        header->resourceIDMapSize = idmap_size;
+    }
     mHeaders.add(header);
 
     const bool notDeviceEndian = htods(0xf0) != 0xf0;
 
     LOAD_TABLE_NOISY(
-        LOGV("Adding resources to ResTable: data=%p, size=0x%x, cookie=%p, asset=%p, copy=%d\n",
-             data, size, cookie, asset, copyData));
+        LOGV("Adding resources to ResTable: data=%p, size=0x%x, cookie=%p, asset=%p, copy=%d "
+             "idmap=%p\n", data, size, cookie, asset, copyData, idmap));
     
     if (copyData || notDeviceEndian) {
         header->ownedData = malloc(size);
@@ -1836,7 +1935,16 @@
                      dtohl(header->header->packageCount));
                 return (mError=BAD_TYPE);
             }
-            if (parsePackage((ResTable_package*)chunk, header) != NO_ERROR) {
+            uint32_t idmap_id = 0;
+            if (idmap != NULL) {
+                uint32_t tmp;
+                if (getIdmapPackageId(header->resourceIDMap,
+                                      header->resourceIDMapSize,
+                                      &tmp) == NO_ERROR) {
+                    idmap_id = tmp;
+                }
+            }
+            if (parsePackage((ResTable_package*)chunk, header, idmap_id) != NO_ERROR) {
                 return mError;
             }
             curPackage++;
@@ -1858,6 +1966,7 @@
     if (mError != NO_ERROR) {
         LOGW("No string values found in resource table!");
     }
+
     TABLE_NOISY(LOGV("Returning from add with mError=%d\n", mError));
     return mError;
 }
@@ -2002,17 +2111,38 @@
     size_t ip = grp->packages.size();
     while (ip > 0) {
         ip--;
+        int T = t;
+        int E = e;
 
         const Package* const package = grp->packages[ip];
+        if (package->header->resourceIDMap) {
+            uint32_t overlayResID = 0x0;
+            status_t retval = idmapLookup(package->header->resourceIDMap,
+                                          package->header->resourceIDMapSize,
+                                          resID, &overlayResID);
+            if (retval == NO_ERROR && overlayResID != 0x0) {
+                // for this loop iteration, this is the type and entry we really want
+                LOGV("resource map 0x%08x -> 0x%08x\n", resID, overlayResID);
+                T = Res_GETTYPE(overlayResID);
+                E = Res_GETENTRY(overlayResID);
+            } else {
+                // resource not present in overlay package, continue with the next package
+                continue;
+            }
+        }
 
         const ResTable_type* type;
         const ResTable_entry* entry;
         const Type* typeClass;
-        ssize_t offset = getEntry(package, t, e, desiredConfig, &type, &entry, &typeClass);
+        ssize_t offset = getEntry(package, T, E, desiredConfig, &type, &entry, &typeClass);
         if (offset <= 0) {
-            if (offset < 0) {
+            // No {entry, appropriate config} pair found in package. If this
+            // package is an overlay package (ip != 0), this simply means the
+            // overlay package did not specify a default.
+            // Non-overlay packages are still required to provide a default.
+            if (offset < 0 && ip == 0) {
                 LOGW("Failure getting entry for 0x%08x (t=%d e=%d) in package %zd (error %d)\n",
-                        resID, t, e, ip, (int)offset);
+                        resID, T, E, ip, (int)offset);
                 rc = offset;
                 goto out;
             }
@@ -2044,13 +2174,16 @@
 
         if (outSpecFlags != NULL) {
             if (typeClass->typeSpecFlags != NULL) {
-                *outSpecFlags |= dtohl(typeClass->typeSpecFlags[e]);
+                *outSpecFlags |= dtohl(typeClass->typeSpecFlags[E]);
             } else {
                 *outSpecFlags = -1;
             }
         }
-        
-        if (bestPackage != NULL && bestItem.isMoreSpecificThan(thisConfig)) {
+
+        if (bestPackage != NULL &&
+            (bestItem.isMoreSpecificThan(thisConfig) || bestItem.diff(thisConfig) == 0)) {
+            // Discard thisConfig not only if bestItem is more specific, but also if the two configs
+            // are identical (diff == 0), or overlay packages will not take effect.
             continue;
         }
         
@@ -2250,21 +2383,45 @@
 
     TABLE_NOISY(LOGI("Building bag: %p\n", (void*)resID));
     
+    ResTable_config bestConfig;
+    memset(&bestConfig, 0, sizeof(bestConfig));
+
     // Now collect all bag attributes from all packages.
     size_t ip = grp->packages.size();
     while (ip > 0) {
         ip--;
+        int T = t;
+        int E = e;
 
         const Package* const package = grp->packages[ip];
+        if (package->header->resourceIDMap) {
+            uint32_t overlayResID = 0x0;
+            status_t retval = idmapLookup(package->header->resourceIDMap,
+                                          package->header->resourceIDMapSize,
+                                          resID, &overlayResID);
+            if (retval == NO_ERROR && overlayResID != 0x0) {
+                // for this loop iteration, this is the type and entry we really want
+                LOGV("resource map 0x%08x -> 0x%08x\n", resID, overlayResID);
+                T = Res_GETTYPE(overlayResID);
+                E = Res_GETENTRY(overlayResID);
+            } else {
+                // resource not present in overlay package, continue with the next package
+                continue;
+            }
+        }
 
         const ResTable_type* type;
         const ResTable_entry* entry;
         const Type* typeClass;
-        LOGV("Getting entry pkg=%p, t=%d, e=%d\n", package, t, e);
-        ssize_t offset = getEntry(package, t, e, &mParams, &type, &entry, &typeClass);
+        LOGV("Getting entry pkg=%p, t=%d, e=%d\n", package, T, E);
+        ssize_t offset = getEntry(package, T, E, &mParams, &type, &entry, &typeClass);
         LOGV("Resulting offset=%d\n", offset);
         if (offset <= 0) {
-            if (offset < 0) {
+            // No {entry, appropriate config} pair found in package. If this
+            // package is an overlay package (ip != 0), this simply means the
+            // overlay package did not specify a default.
+            // Non-overlay packages are still required to provide a default.
+            if (offset < 0 && ip == 0) {
                 if (set) free(set);
                 return offset;
             }
@@ -2277,6 +2434,15 @@
             continue;
         }
 
+        if (set != NULL && !type->config.isBetterThan(bestConfig, NULL)) {
+            continue;
+        }
+        bestConfig = type->config;
+        if (set) {
+            free(set);
+            set = NULL;
+        }
+
         const uint16_t entrySize = dtohs(entry->size);
         const uint32_t parent = entrySize >= sizeof(ResTable_map_entry)
             ? dtohl(((const ResTable_map_entry*)entry)->parent.ident) : 0;
@@ -2288,43 +2454,41 @@
         TABLE_NOISY(LOGI("Found map: size=%p parent=%p count=%d\n",
                          entrySize, parent, count));
 
-        if (set == NULL) {
-            // If this map inherits from another, we need to start
-            // with its parent's values.  Otherwise start out empty.
-            TABLE_NOISY(printf("Creating new bag, entrySize=0x%08x, parent=0x%08x\n",
-                         entrySize, parent));
-            if (parent) {
-                const bag_entry* parentBag;
-                uint32_t parentTypeSpecFlags = 0;
-                const ssize_t NP = getBagLocked(parent, &parentBag, &parentTypeSpecFlags);
-                const size_t NT = ((NP >= 0) ? NP : 0) + N;
-                set = (bag_set*)malloc(sizeof(bag_set)+sizeof(bag_entry)*NT);
-                if (set == NULL) {
-                    return NO_MEMORY;
-                }
-                if (NP > 0) {
-                    memcpy(set+1, parentBag, NP*sizeof(bag_entry));
-                    set->numAttrs = NP;
-                    TABLE_NOISY(LOGI("Initialized new bag with %d inherited attributes.\n", NP));
-                } else {
-                    TABLE_NOISY(LOGI("Initialized new bag with no inherited attributes.\n"));
-                    set->numAttrs = 0;
-                }
-                set->availAttrs = NT;
-                set->typeSpecFlags = parentTypeSpecFlags;
-            } else {
-                set = (bag_set*)malloc(sizeof(bag_set)+sizeof(bag_entry)*N);
-                if (set == NULL) {
-                    return NO_MEMORY;
-                }
-                set->numAttrs = 0;
-                set->availAttrs = N;
-                set->typeSpecFlags = 0;
+        // If this map inherits from another, we need to start
+        // with its parent's values.  Otherwise start out empty.
+        TABLE_NOISY(printf("Creating new bag, entrySize=0x%08x, parent=0x%08x\n",
+                           entrySize, parent));
+        if (parent) {
+            const bag_entry* parentBag;
+            uint32_t parentTypeSpecFlags = 0;
+            const ssize_t NP = getBagLocked(parent, &parentBag, &parentTypeSpecFlags);
+            const size_t NT = ((NP >= 0) ? NP : 0) + N;
+            set = (bag_set*)malloc(sizeof(bag_set)+sizeof(bag_entry)*NT);
+            if (set == NULL) {
+                return NO_MEMORY;
             }
+            if (NP > 0) {
+                memcpy(set+1, parentBag, NP*sizeof(bag_entry));
+                set->numAttrs = NP;
+                TABLE_NOISY(LOGI("Initialized new bag with %d inherited attributes.\n", NP));
+            } else {
+                TABLE_NOISY(LOGI("Initialized new bag with no inherited attributes.\n"));
+                set->numAttrs = 0;
+            }
+            set->availAttrs = NT;
+            set->typeSpecFlags = parentTypeSpecFlags;
+        } else {
+            set = (bag_set*)malloc(sizeof(bag_set)+sizeof(bag_entry)*N);
+            if (set == NULL) {
+                return NO_MEMORY;
+            }
+            set->numAttrs = 0;
+            set->availAttrs = N;
+            set->typeSpecFlags = 0;
         }
 
         if (typeClass->typeSpecFlags != NULL) {
-            set->typeSpecFlags |= dtohl(typeClass->typeSpecFlags[e]);
+            set->typeSpecFlags |= dtohl(typeClass->typeSpecFlags[E]);
         } else {
             set->typeSpecFlags = -1;
         }
@@ -3901,7 +4065,7 @@
 }
 
 status_t ResTable::parsePackage(const ResTable_package* const pkg,
-                                const Header* const header)
+                                const Header* const header, uint32_t idmap_id)
 {
     const uint8_t* base = (const uint8_t*)pkg;
     status_t err = validate_chunk(&pkg->header, sizeof(*pkg),
@@ -3935,8 +4099,12 @@
     
     Package* package = NULL;
     PackageGroup* group = NULL;
-    uint32_t id = dtohl(pkg->id);
-    if (id != 0 && id < 256) {
+    uint32_t id = idmap_id != 0 ? idmap_id : dtohl(pkg->id);
+    // If at this point id == 0, pkg is an overlay package without a
+    // corresponding idmap. During regular usage, overlay packages are
+    // always loaded alongside their idmaps, but during idmap creation
+    // the package is temporarily loaded by itself.
+    if (id < 256) {
     
         package = new Package(this, header, pkg);
         if (package == NULL) {
@@ -3989,7 +4157,7 @@
             return (mError=err);
         }
     } else {
-        LOG_ALWAYS_FATAL("Skins not supported!");
+        LOG_ALWAYS_FATAL("Package id out of range");
         return NO_ERROR;
     }
 
@@ -4144,6 +4312,136 @@
     return NO_ERROR;
 }
 
+status_t ResTable::createIdmap(const ResTable& overlay, uint32_t originalCrc, uint32_t overlayCrc,
+                               void** outData, size_t* outSize) const
+{
+    // see README for details on the format of map
+    if (mPackageGroups.size() == 0) {
+        return UNKNOWN_ERROR;
+    }
+    if (mPackageGroups[0]->packages.size() == 0) {
+        return UNKNOWN_ERROR;
+    }
+
+    Vector<Vector<uint32_t> > map;
+    const PackageGroup* pg = mPackageGroups[0];
+    const Package* pkg = pg->packages[0];
+    size_t typeCount = pkg->types.size();
+    // starting size is header + first item (number of types in map)
+    *outSize = (IDMAP_HEADER_SIZE + 1) * sizeof(uint32_t);
+    const String16 overlayPackage(overlay.mPackageGroups[0]->packages[0]->package->name);
+    const uint32_t pkg_id = pkg->package->id << 24;
+
+    for (size_t typeIndex = 0; typeIndex < typeCount; ++typeIndex) {
+        ssize_t offset = -1;
+        const Type* typeConfigs = pkg->getType(typeIndex);
+        ssize_t mapIndex = map.add();
+        if (mapIndex < 0) {
+            return NO_MEMORY;
+        }
+        Vector<uint32_t>& vector = map.editItemAt(mapIndex);
+        for (size_t entryIndex = 0; entryIndex < typeConfigs->entryCount; ++entryIndex) {
+            uint32_t resID = (0xff000000 & ((pkg->package->id)<<24))
+                | (0x00ff0000 & ((typeIndex+1)<<16))
+                | (0x0000ffff & (entryIndex));
+            resource_name resName;
+            if (!this->getResourceName(resID, &resName)) {
+                return UNKNOWN_ERROR;
+            }
+
+            const String16 overlayType(resName.type, resName.typeLen);
+            const String16 overlayName(resName.name, resName.nameLen);
+            uint32_t overlayResID = overlay.identifierForName(overlayName.string(),
+                                                              overlayName.size(),
+                                                              overlayType.string(),
+                                                              overlayType.size(),
+                                                              overlayPackage.string(),
+                                                              overlayPackage.size());
+            if (overlayResID != 0) {
+                // overlay package has package ID == 0, use original package's ID instead
+                overlayResID |= pkg_id;
+            }
+            vector.push(overlayResID);
+            if (overlayResID != 0 && offset == -1) {
+                offset = Res_GETENTRY(resID);
+            }
+#if 0
+            if (overlayResID != 0) {
+                LOGD("%s/%s 0x%08x -> 0x%08x\n",
+                     String8(String16(resName.type)).string(),
+                     String8(String16(resName.name)).string(),
+                     resID, overlayResID);
+            }
+#endif
+        }
+
+        if (offset != -1) {
+            // shave off leading and trailing entries which lack overlay values
+            vector.removeItemsAt(0, offset);
+            vector.insertAt((uint32_t)offset, 0, 1);
+            while (vector.top() == 0) {
+                vector.pop();
+            }
+            // reserve space for number and offset of entries, and the actual entries
+            *outSize += (2 + vector.size()) * sizeof(uint32_t);
+        } else {
+            // no entries of current type defined in overlay package
+            vector.clear();
+            // reserve space for type offset
+            *outSize += 1 * sizeof(uint32_t);
+        }
+    }
+
+    if ((*outData = malloc(*outSize)) == NULL) {
+        return NO_MEMORY;
+    }
+    uint32_t* data = (uint32_t*)*outData;
+    *data++ = htodl(IDMAP_MAGIC);
+    *data++ = htodl(originalCrc);
+    *data++ = htodl(overlayCrc);
+    const size_t mapSize = map.size();
+    *data++ = htodl(mapSize);
+    size_t offset = mapSize;
+    for (size_t i = 0; i < mapSize; ++i) {
+        const Vector<uint32_t>& vector = map.itemAt(i);
+        const size_t N = vector.size();
+        if (N == 0) {
+            *data++ = htodl(0);
+        } else {
+            offset++;
+            *data++ = htodl(offset);
+            offset += N;
+        }
+    }
+    for (size_t i = 0; i < mapSize; ++i) {
+        const Vector<uint32_t>& vector = map.itemAt(i);
+        const size_t N = vector.size();
+        if (N == 0) {
+            continue;
+        }
+        *data++ = htodl(N - 1); // do not count the offset (which is vector's first element)
+        for (size_t j = 0; j < N; ++j) {
+            const uint32_t& overlayResID = vector.itemAt(j);
+            *data++ = htodl(overlayResID);
+        }
+    }
+
+    return NO_ERROR;
+}
+
+bool ResTable::getIdmapInfo(const void* idmap, size_t sizeBytes,
+                            uint32_t* pOriginalCrc, uint32_t* pOverlayCrc)
+{
+    const uint32_t* map = (const uint32_t*)idmap;
+    if (!assertIdmapHeader(map, sizeBytes)) {
+        return false;
+    }
+    *pOriginalCrc = map[1];
+    *pOverlayCrc = map[2];
+    return true;
+}
+
+
 #ifndef HAVE_ANDROID_OS
 #define CHAR16_TO_CSTR(c16, len) (String8(String16(c16,len)).string())
 
diff --git a/location/java/com/android/internal/location/GpsNetInitiatedHandler.java b/location/java/com/android/internal/location/GpsNetInitiatedHandler.java
index ffc3346..29dec63 100755
--- a/location/java/com/android/internal/location/GpsNetInitiatedHandler.java
+++ b/location/java/com/android/internal/location/GpsNetInitiatedHandler.java
@@ -205,7 +205,7 @@
             mNiNotification.defaults &= ~Notification.DEFAULT_SOUND;
         }        
 
-        mNiNotification.flags = Notification.FLAG_ONGOING_EVENT;
+        mNiNotification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;
         mNiNotification.tickerText = getNotifTicker(notif, mContext);
 
         // if not to popup dialog immediately, pending intent will open the dialog
diff --git a/media/java/android/media/ThumbnailUtils.java b/media/java/android/media/ThumbnailUtils.java
index 7fdf448..7c181ee 100644
--- a/media/java/android/media/ThumbnailUtils.java
+++ b/media/java/android/media/ThumbnailUtils.java
@@ -83,7 +83,7 @@
      *
      * @param filePath the path of image file
      * @param kind could be MINI_KIND or MICRO_KIND
-     * @return Bitmap
+     * @return Bitmap, or null on failures
      *
      * @hide This method is only used by media framework and media provider internally.
      */
@@ -123,6 +123,8 @@
                 bitmap = BitmapFactory.decodeFileDescriptor(fd, null, options);
             } catch (IOException ex) {
                 Log.e(TAG, "", ex);
+            } catch (OutOfMemoryError oom) {
+                Log.e(TAG, "Unable to decode file " + filePath + ". OutOfMemoryError.", oom);
             }
         }
 
diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp
index 2caf211..a156da6 100644
--- a/media/libstagefright/HTTPStream.cpp
+++ b/media/libstagefright/HTTPStream.cpp
@@ -139,6 +139,9 @@
         int s, void *data, size_t size, int flags, bool sendData) {
     ssize_t result = 0;
 
+    if (s < 0) {
+        return -1;
+    }
     while (size > 0) {
         fd_set rs, ws, es;
         FD_ZERO(&rs);
diff --git a/media/libstagefright/codecs/aacenc/SampleCode/AAC_E_SAMPLES.c b/media/libstagefright/codecs/aacenc/SampleCode/AAC_E_SAMPLES.c
index 64d012d..1cee117 100644
--- a/media/libstagefright/codecs/aacenc/SampleCode/AAC_E_SAMPLES.c
+++ b/media/libstagefright/codecs/aacenc/SampleCode/AAC_E_SAMPLES.c
@@ -1,283 +1,283 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		AAC_E_SAMPLES.h

-

-	Content:	sample code for AAC encoder

-

-*******************************************************************************/

-

-#include		<dlfcn.h>

-#include		<stdio.h>

-#include		<stdlib.h>

-#include		<string.h>

-#include		<time.h>

-#include		"voAAC.h"

-#include		"cmnMemory.h"

-

-#define  VO_AAC_E_OUTPUT	  1

-#define READ_SIZE	(1024*8)	

-unsigned char outBuf[1024*8];

-unsigned char inBuf[READ_SIZE];

-

-const char* HelpString = 

-"VisualOn AAC encoder Usage:\n"

-"voAACEncTest -if <inputfile.pcm> -of <outputfile.aac> -sr <samplerate> -ch <channel> -br <bitrate> -adts <adts> \n"

-"-if input file name \n"

-"-of output file name \n"

-"-sr input pcm samplerate, default 44100 \n"

-"-ch input pcm channel, default 2 channel \n"

-"-br encoded aac bitrate, default 64000 * (samplerate/100)*channel/441(480)\n"

-"-adts add or no adts header, default add adts header\n"

-"For example: \n"

-"./voAACEncTest -if raw.pcm -of raw.aac -sr 44100 -ch 2 -br 128000\n";

-

-static int parsecmdline(int argc, char **argv,char  **input_filename, char  **output_filename, AACENC_PARAM *param)

-{

-	// notice that:

-	// bitRate/nChannels > 8000

-	// bitRate/nChannels < 160000 

-	// bitRate/nChannels < sampleRate*6

-	param->adtsUsed = 1;

-	param->bitRate = 0;

-	param->nChannels = 2;

-	param->sampleRate = 44100;

-

-	if(argc < 5 || argc > 13)

-	{

-		return -1;

-	}

-

-	argc--;

-	argv++;

-	while (argc > 0)

-	{

-		if (!strcmp(*argv, "-if"))

-		{

-			argv++;

-			argc--;

-			*input_filename = *argv; 

-		}

-		else if (!strcmp(*argv, "-of"))

-		{

-			argv++;

-			argc--;

-			*output_filename = *argv;

-		}

-		else if (!strcmp(*argv, "-sr"))

-		{

-			argv++;

-			argc--;

-			param->sampleRate = atoi(*argv);

-		}

-		else if (!strcmp(*argv, "-ch"))

-		{

-			argv++;

-			argc--;

-			param->nChannels = atoi(*argv);

-		}

-		else if (!strcmp(*argv, "-br"))

-		{

-			argv++;

-			argc--;

-			param->bitRate = atoi(*argv);

-		}

-		else if(!strcmp(*argv, "-adts"))

-		{

-			argv++;

-			argc--;

-			param->adtsUsed = atoi(*argv);

-		}

-		else

-		{

-			return -1;

-		}

-

-		argv++;

-		argc--;

-	}

-

-	if(param->bitRate == 0)

-	{

-		int scale = 441;

-		if(param->sampleRate%8000 == 0)

-			scale = 480;

-		param->bitRate = 640*param->nChannels*param->sampleRate/scale;

-	}

-

-	return 0;

-}

-

-int ReadFile2Buf(FILE* infile,unsigned char* dest,int readSize)

-{

-	int readBytes = 0;

-	readBytes = fread(dest, 1, readSize, infile);

-	return readBytes;

-}

-

-typedef int (VO_API * VOGETAUDIODECAPI) (VO_AUDIO_CODECAPI * pDecHandle);

-

-int main(int argc, char **argv)

-{

-	FILE						*infile, *outfile;

-	int							t1, t2;

-	VO_AUDIO_CODECAPI			AudioAPI;

-	VO_MEM_OPERATOR				moper;

-	VO_CODEC_INIT_USERDATA		useData;

-	VO_HANDLE					hCodec;

-	VO_CODECBUFFER				inData;

-	VO_CODECBUFFER				outData;

-	VO_AUDIO_OUTPUTINFO			outInfo;

-    int							firstWrite = 1;

-	int							eofFile = 0;

-	int							*info=(int*)inBuf;

-	int							bytesLeft, nRead;

-	int							EncoderdFrame = 0;

-	int							total = 0;

-	int							isOutput = 1;

-	int							returnCode;

-	AACENC_PARAM				aacpara;

-	void						*handle;

-	void						*pfunc;

-	VOGETAUDIODECAPI			pGetAPI;

-	const char					*infileName = NULL;

-    const char					*outfileName = NULL;

-

-	returnCode = parsecmdline(argc,argv, &infileName, &outfileName, &aacpara);

-	if(returnCode)

-	{

-		printf("%s", HelpString);

-		return 0;

-	}

-

-	/* open input file */

-	infile = fopen(infileName, "rb");

-	if (!infile) {

-		printf("Open input file fail...");

-		return -1;

-	}

-

-	/* open output file */

-	if(isOutput)

-	{

-		outfile = fopen(outfileName, "wb"); 

-		if (!outfile) {

-			printf("Open output file fail...");

-			return -1;

-		}

-	}

-	// set memory operators;

-	moper.Alloc = cmnMemAlloc;

-	moper.Copy = cmnMemCopy;

-	moper.Free = cmnMemFree;

-	moper.Set = cmnMemSet;

-	moper.Check = cmnMemCheck;

-	useData.memflag = VO_IMF_USERMEMOPERATOR;

-	useData.memData = (VO_PTR)(&moper);

-	// open encoder dll;

-	handle = dlopen("/data/local/tmp/libvoAACEncv7.so", RTLD_NOW);

-	if(handle == 0)

-	{

-		printf("open dll error......");

-		return -1;

-	}

-	// Get API;

-	pfunc = dlsym(handle, "voGetAACEncAPI");	

-	if(pfunc == 0)

-	{

-		printf("open function error......");

-		return -1;

-	}

-	pGetAPI = (VOGETAUDIODECAPI)pfunc;

-	returnCode  = pGetAPI(&AudioAPI);

-	if(returnCode)

-		return -1;

-

-

-//#######################################   Init Encoding Section   #########################################

-	returnCode = AudioAPI.Init(&hCodec, VO_AUDIO_CodingAAC, &useData);

-	if(returnCode < 0)

-	{

-		printf("#### VOI_Error2:fail to initialize the Encoderr###\n");

-		return -1;

-	}

-

-	returnCode = AudioAPI.SetParam(hCodec, VO_PID_AAC_ENCPARAM, &aacpara);	

-	

-	inData.Buffer = inBuf;

-	bytesLeft = ReadFile2Buf(infile,inData.Buffer,READ_SIZE);

-

-//#######################################    Encoding Section   #########################################

-	

-	do {

-

-		inData.Length    = bytesLeft;

-		outData.Buffer   = outBuf;

-		outData.Length = 1024*8;

-

-		t1 = clock();

-		

-		returnCode = AudioAPI.SetInputData(hCodec,&inData);

-		

-		do {

-			outData.Buffer   = outBuf;

-			outData.Length = 1024*8;

-

-			returnCode = AudioAPI.GetOutputData(hCodec,&outData, &outInfo);

-

-			if(returnCode == 0)

-				EncoderdFrame++;

-			if(returnCode == VO_ERR_LICENSE_ERROR)

-				break;

-

-#if VO_AAC_E_OUTPUT

-			if (isOutput && returnCode == 0)

-			{

-				fwrite(outData.Buffer, 1, outData.Length, outfile);

-			}

-#endif

-		} while(returnCode != (VO_ERR_INPUT_BUFFER_SMALL));

-

-		if(returnCode == VO_ERR_LICENSE_ERROR)

-			break;

-

-		t2 = clock();

-		total += t2 - t1;

-

-		if (!eofFile) {

-			nRead = ReadFile2Buf(infile, inBuf,READ_SIZE);

-			bytesLeft = nRead;

-			inData.Buffer = inBuf;

-			if (feof(infile))

-				eofFile = 1;

-		}

-

-	} while (!eofFile && returnCode);

-

-

-//################################################  End Encoding Section  #######################################################

-	returnCode = AudioAPI.Uninit(hCodec);

-

-	fclose(infile);

-	if (outfile)

-    {

-        fclose(outfile);

-    }

-	dlclose(handle);

-	return 0;

-}

-

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		AAC_E_SAMPLES.h
+
+	Content:	sample code for AAC encoder
+
+*******************************************************************************/
+
+#include		<dlfcn.h>
+#include		<stdio.h>
+#include		<stdlib.h>
+#include		<string.h>
+#include		<time.h>
+#include		"voAAC.h"
+#include		"cmnMemory.h"
+
+#define  VO_AAC_E_OUTPUT	  1
+#define READ_SIZE	(1024*8)	
+unsigned char outBuf[1024*8];
+unsigned char inBuf[READ_SIZE];
+
+const char* HelpString = 
+"VisualOn AAC encoder Usage:\n"
+"voAACEncTest -if <inputfile.pcm> -of <outputfile.aac> -sr <samplerate> -ch <channel> -br <bitrate> -adts <adts> \n"
+"-if input file name \n"
+"-of output file name \n"
+"-sr input pcm samplerate, default 44100 \n"
+"-ch input pcm channel, default 2 channel \n"
+"-br encoded aac bitrate, default 64000 * (samplerate/100)*channel/441(480)\n"
+"-adts add or no adts header, default add adts header\n"
+"For example: \n"
+"./voAACEncTest -if raw.pcm -of raw.aac -sr 44100 -ch 2 -br 128000\n";
+
+static int parsecmdline(int argc, char **argv,char  **input_filename, char  **output_filename, AACENC_PARAM *param)
+{
+	// notice that:
+	// bitRate/nChannels > 8000
+	// bitRate/nChannels < 160000 
+	// bitRate/nChannels < sampleRate*6
+	param->adtsUsed = 1;
+	param->bitRate = 0;
+	param->nChannels = 2;
+	param->sampleRate = 44100;
+
+	if(argc < 5 || argc > 13)
+	{
+		return -1;
+	}
+
+	argc--;
+	argv++;
+	while (argc > 0)
+	{
+		if (!strcmp(*argv, "-if"))
+		{
+			argv++;
+			argc--;
+			*input_filename = *argv; 
+		}
+		else if (!strcmp(*argv, "-of"))
+		{
+			argv++;
+			argc--;
+			*output_filename = *argv;
+		}
+		else if (!strcmp(*argv, "-sr"))
+		{
+			argv++;
+			argc--;
+			param->sampleRate = atoi(*argv);
+		}
+		else if (!strcmp(*argv, "-ch"))
+		{
+			argv++;
+			argc--;
+			param->nChannels = atoi(*argv);
+		}
+		else if (!strcmp(*argv, "-br"))
+		{
+			argv++;
+			argc--;
+			param->bitRate = atoi(*argv);
+		}
+		else if(!strcmp(*argv, "-adts"))
+		{
+			argv++;
+			argc--;
+			param->adtsUsed = atoi(*argv);
+		}
+		else
+		{
+			return -1;
+		}
+
+		argv++;
+		argc--;
+	}
+
+	if(param->bitRate == 0)
+	{
+		int scale = 441;
+		if(param->sampleRate%8000 == 0)
+			scale = 480;
+		param->bitRate = 640*param->nChannels*param->sampleRate/scale;
+	}
+
+	return 0;
+}
+
+int ReadFile2Buf(FILE* infile,unsigned char* dest,int readSize)
+{
+	int readBytes = 0;
+	readBytes = fread(dest, 1, readSize, infile);
+	return readBytes;
+}
+
+typedef int (VO_API * VOGETAUDIODECAPI) (VO_AUDIO_CODECAPI * pDecHandle);
+
+int main(int argc, char **argv)
+{
+	FILE						*infile, *outfile;
+	int							t1, t2;
+	VO_AUDIO_CODECAPI			AudioAPI;
+	VO_MEM_OPERATOR				moper;
+	VO_CODEC_INIT_USERDATA		useData;
+	VO_HANDLE					hCodec;
+	VO_CODECBUFFER				inData;
+	VO_CODECBUFFER				outData;
+	VO_AUDIO_OUTPUTINFO			outInfo;
+    int							firstWrite = 1;
+	int							eofFile = 0;
+	int							*info=(int*)inBuf;
+	int							bytesLeft, nRead;
+	int							EncoderdFrame = 0;
+	int							total = 0;
+	int							isOutput = 1;
+	int							returnCode;
+	AACENC_PARAM				aacpara;
+	void						*handle;
+	void						*pfunc;
+	VOGETAUDIODECAPI			pGetAPI;
+	const char					*infileName = NULL;
+    const char					*outfileName = NULL;
+
+	returnCode = parsecmdline(argc,argv, &infileName, &outfileName, &aacpara);
+	if(returnCode)
+	{
+		printf("%s", HelpString);
+		return 0;
+	}
+
+	/* open input file */
+	infile = fopen(infileName, "rb");
+	if (!infile) {
+		printf("Open input file fail...");
+		return -1;
+	}
+
+	/* open output file */
+	if(isOutput)
+	{
+		outfile = fopen(outfileName, "wb"); 
+		if (!outfile) {
+			printf("Open output file fail...");
+			return -1;
+		}
+	}
+	// set memory operators;
+	moper.Alloc = cmnMemAlloc;
+	moper.Copy = cmnMemCopy;
+	moper.Free = cmnMemFree;
+	moper.Set = cmnMemSet;
+	moper.Check = cmnMemCheck;
+	useData.memflag = VO_IMF_USERMEMOPERATOR;
+	useData.memData = (VO_PTR)(&moper);
+	// open encoder dll;
+	handle = dlopen("/data/local/tmp/libvoAACEncv7.so", RTLD_NOW);
+	if(handle == 0)
+	{
+		printf("open dll error......");
+		return -1;
+	}
+	// Get API;
+	pfunc = dlsym(handle, "voGetAACEncAPI");	
+	if(pfunc == 0)
+	{
+		printf("open function error......");
+		return -1;
+	}
+	pGetAPI = (VOGETAUDIODECAPI)pfunc;
+	returnCode  = pGetAPI(&AudioAPI);
+	if(returnCode)
+		return -1;
+
+
+//#######################################   Init Encoding Section   #########################################
+	returnCode = AudioAPI.Init(&hCodec, VO_AUDIO_CodingAAC, &useData);
+	if(returnCode < 0)
+	{
+		printf("#### VOI_Error2:fail to initialize the Encoderr###\n");
+		return -1;
+	}
+
+	returnCode = AudioAPI.SetParam(hCodec, VO_PID_AAC_ENCPARAM, &aacpara);	
+	
+	inData.Buffer = inBuf;
+	bytesLeft = ReadFile2Buf(infile,inData.Buffer,READ_SIZE);
+
+//#######################################    Encoding Section   #########################################
+	
+	do {
+
+		inData.Length    = bytesLeft;
+		outData.Buffer   = outBuf;
+		outData.Length = 1024*8;
+
+		t1 = clock();
+		
+		returnCode = AudioAPI.SetInputData(hCodec,&inData);
+		
+		do {
+			outData.Buffer   = outBuf;
+			outData.Length = 1024*8;
+
+			returnCode = AudioAPI.GetOutputData(hCodec,&outData, &outInfo);
+
+			if(returnCode == 0)
+				EncoderdFrame++;
+			if(returnCode == VO_ERR_LICENSE_ERROR)
+				break;
+
+#if VO_AAC_E_OUTPUT
+			if (isOutput && returnCode == 0)
+			{
+				fwrite(outData.Buffer, 1, outData.Length, outfile);
+			}
+#endif
+		} while(returnCode != (VO_ERR_INPUT_BUFFER_SMALL));
+
+		if(returnCode == VO_ERR_LICENSE_ERROR)
+			break;
+
+		t2 = clock();
+		total += t2 - t1;
+
+		if (!eofFile) {
+			nRead = ReadFile2Buf(infile, inBuf,READ_SIZE);
+			bytesLeft = nRead;
+			inData.Buffer = inBuf;
+			if (feof(infile))
+				eofFile = 1;
+		}
+
+	} while (!eofFile && returnCode);
+
+
+//################################################  End Encoding Section  #######################################################
+	returnCode = AudioAPI.Uninit(hCodec);
+
+	fclose(infile);
+	if (outfile)
+    {
+        fclose(outfile);
+    }
+	dlclose(handle);
+	return 0;
+}
+
+
diff --git a/media/libstagefright/codecs/aacenc/SampleCode/eclair/Makefile b/media/libstagefright/codecs/aacenc/SampleCode/eclair/Makefile
index 22c5dc1..2825e8e 100644
--- a/media/libstagefright/codecs/aacenc/SampleCode/eclair/Makefile
+++ b/media/libstagefright/codecs/aacenc/SampleCode/eclair/Makefile
@@ -1,55 +1,55 @@
-#/*

-#** Copyright 2003-2010, VisualOn, Inc.

-#**

-#** Licensed under the Apache License, Version 2.0 (the "License");

-#** you may not use this file except in compliance with the License.

-#** You may obtain a copy of the License at

-#**

-#**     http://www.apache.org/licenses/LICENSE-2.0

-#**

-#** Unless required by applicable law or agreed to in writing, software

-#** distributed under the License is distributed on an "AS IS" BASIS,

-#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

-#** See the License for the specific language governing permissions and

-#** limitations under the License.

-#*/

-

-# target6

-# available: pc, v4(armv4), v5(armv5), v5x(armv5 xscale), v6(armv6), v7(cortex-a8 neon)

-VOTT:= v7

-

-

-# module type

-# please specify the type of your module: lib or exe

-VOMT:= exe

-

-

-# module macros

-# please append the additional macro definitions here for your module if necessary. 

-# e.g. -DVISUALON, macro VISUALON defined for your module 

-VOMM:= #ARMV5E

-

-

-

-# please specify the name of your module

-VOTARGET:= voAACEncTestv7

-

-

-# please modify here to be sure to see the g1.mk

-include ../../../../Tools/eclair.mk 

-

-# dependent libraries.

-VODEPLIBS:=-ldl

-

-# module source

-# please modify here to be sure to see the ms.mk which specifies all source info of your module

-include ../ms.mk

-

-

-# please specify where is the voRelease on your PC, relative path is suggested

-VORELDIR:=../../../../../Release/

-

-

-# please modify here to be sure to see the doit.mk

-include ../../../../Tools/doit.mk 

-

+#/*
+#** Copyright 2003-2010, VisualOn, Inc.
+#**
+#** Licensed under the Apache License, Version 2.0 (the "License");
+#** you may not use this file except in compliance with the License.
+#** You may obtain a copy of the License at
+#**
+#**     http://www.apache.org/licenses/LICENSE-2.0
+#**
+#** Unless required by applicable law or agreed to in writing, software
+#** distributed under the License is distributed on an "AS IS" BASIS,
+#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#** See the License for the specific language governing permissions and
+#** limitations under the License.
+#*/
+
+# target6
+# available: pc, v4(armv4), v5(armv5), v5x(armv5 xscale), v6(armv6), v7(cortex-a8 neon)
+VOTT:= v7
+
+
+# module type
+# please specify the type of your module: lib or exe
+VOMT:= exe
+
+
+# module macros
+# please append the additional macro definitions here for your module if necessary. 
+# e.g. -DVISUALON, macro VISUALON defined for your module 
+VOMM:= #ARMV5E
+
+
+
+# please specify the name of your module
+VOTARGET:= voAACEncTestv7
+
+
+# please modify here to be sure to see the g1.mk
+include ../../../../Tools/eclair.mk 
+
+# dependent libraries.
+VODEPLIBS:=-ldl
+
+# module source
+# please modify here to be sure to see the ms.mk which specifies all source info of your module
+include ../ms.mk
+
+
+# please specify where is the voRelease on your PC, relative path is suggested
+VORELDIR:=../../../../../Release/
+
+
+# please modify here to be sure to see the doit.mk
+include ../../../../Tools/doit.mk 
+
diff --git a/media/libstagefright/codecs/aacenc/SampleCode/ms.mk b/media/libstagefright/codecs/aacenc/SampleCode/ms.mk
index 771a569..f7f06b3 100644
--- a/media/libstagefright/codecs/aacenc/SampleCode/ms.mk
+++ b/media/libstagefright/codecs/aacenc/SampleCode/ms.mk
@@ -1,23 +1,23 @@
-#/*

-#** Copyright 2003-2010, VisualOn, Inc.

-#**

-#** Licensed under the Apache License, Version 2.0 (the "License");

-#** you may not use this file except in compliance with the License.

-#** You may obtain a copy of the License at

-#**

-#**     http://www.apache.org/licenses/LICENSE-2.0

-#**

-#** Unless required by applicable law or agreed to in writing, software

-#** distributed under the License is distributed on an "AS IS" BASIS,

-#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

-#** See the License for the specific language governing permissions and

-#** limitations under the License.

-#*/

-

-# please list all objects needed by your target here

-OBJS:=AAC_E_SAMPLES.o	cmnMemory.o

-			

-# please list all directories that all source files relative with your module(.h .c .cpp) locate 

-VOSRCDIR:=../ ../../../../include  ../../../../Common

-					

-				

+#/*
+#** Copyright 2003-2010, VisualOn, Inc.
+#**
+#** Licensed under the Apache License, Version 2.0 (the "License");
+#** you may not use this file except in compliance with the License.
+#** You may obtain a copy of the License at
+#**
+#**     http://www.apache.org/licenses/LICENSE-2.0
+#**
+#** Unless required by applicable law or agreed to in writing, software
+#** distributed under the License is distributed on an "AS IS" BASIS,
+#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#** See the License for the specific language governing permissions and
+#** limitations under the License.
+#*/
+
+# please list all objects needed by your target here
+OBJS:=AAC_E_SAMPLES.o	cmnMemory.o
+			
+# please list all directories that all source files relative with your module(.h .c .cpp) locate 
+VOSRCDIR:=../ ../../../../include  ../../../../Common
+					
+				
diff --git a/media/libstagefright/codecs/aacenc/basic_op/basic_op.h b/media/libstagefright/codecs/aacenc/basic_op/basic_op.h
index 5457f33..8291684a 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/basic_op.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/basic_op.h
@@ -1,27 +1,27 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		basicop2.h

-

-	Content:	Constants , Globals and Basic arithmetic operators.

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		basicop2.h
+
+	Content:	Constants , Globals and Basic arithmetic operators.
+
 *******************************************************************************/
 
 #ifndef __BASIC_OP_H
-#define __BASIC_OP_H

+#define __BASIC_OP_H
 
 #include "typedef.h"
 
@@ -30,1137 +30,1137 @@
 
 #define MAX_16 (Word16)0x7fff
 #define MIN_16 (Word16)0x8000
-#define ABS(a)	((a) >= 0) ? (a) : (-(a))

-

-/* Short abs,           1   */

-#define abs_s(x)       ((Word16)(((x) != MIN_16) ? (((x) >= 0) ? (x) : (-(x))) : MAX_16))

-

-/* 16 bit var1 -> MSB,     2 */

-#define L_deposit_h(x) (((Word32)(x)) << 16)

-

-

-/* 16 bit var1 -> LSB,     2 */

-#define L_deposit_l(x) ((Word32)(x))

-

-

-/* Long abs,              3  */

-#define L_abs(x) (((x) != MIN_32) ? (((x) >= 0) ? (x) : (-(x))) : MAX_32)

-

-

-/* Short negate,        1   */

-#define negate(var1) ((Word16)(((var1) == MIN_16) ? MAX_16 : (-(var1))))

-

-

-/* Long negate,     2 */

-#define L_negate(L_var1) (((L_var1) == (MIN_32)) ? (MAX_32) : (-(L_var1)))

-

-

-#define MULHIGH(A,B) (int)(((Word64)(A)*(Word64)(B)) >> 32)

-#define fixmul(a, b) (int)((((Word64)(a)*(Word64)(b)) >> 32) << 1)

-

-

-#if  (SATRUATE_IS_INLINE)

-__inline Word16 saturate(Word32 L_var1);

-#else

-Word16 saturate(Word32 L_var1);

-#endif

-

-/* Short shift left,    1   */

-#if (SHL_IS_INLINE)

-__inline Word16 shl (Word16 var1, Word16 var2);

-#else

-Word16 shl (Word16 var1, Word16 var2);

-#endif

-

-/* Short shift right,   1   */

-#if (SHR_IS_INLINE)

-__inline Word16 shr (Word16 var1, Word16 var2);

-#else

-Word16 shr (Word16 var1, Word16 var2);

-#endif

-

-#if (L_MULT_IS_INLINE)

-__inline Word32 L_mult(Word16 var1, Word16 var2);

-#else

-Word32 L_mult(Word16 var1, Word16 var2);

-#endif

-

-/* Msu,  1  */

-#if (L_MSU_IS_INLINE)

-__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);

-#else

-Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);

-#endif

-    

-/* Long sub,        2 */

-#if (L_SUB_IS_INLINE)

-__inline Word32 L_sub(Word32 L_var1, Word32 L_var2);

-#else

-Word32 L_sub(Word32 L_var1, Word32 L_var2);

-#endif

-

-/* Long shift left, 2 */

-#if (L_SHL_IS_INLINE)

-__inline Word32 L_shl (Word32 L_var1, Word16 var2);

-#else

-Word32 L_shl (Word32 L_var1, Word16 var2);

-#endif

-

-/* Long shift right, 2*/

-#if (L_SHR_IS_INLINE)

-__inline Word32 L_shr (Word32 L_var1, Word16 var2);

-#else

-Word32 L_shr (Word32 L_var1, Word16 var2);

-#endif

-

-/* Short add,           1   */

-#if (ADD_IS_INLINE)

-__inline Word16 add (Word16 var1, Word16 var2);

-#else

-Word16 add (Word16 var1, Word16 var2);

-#endif

-    

-/* Short sub,           1   */

-#if (SUB_IS_INLINE)

-__inline Word16 sub(Word16 var1, Word16 var2);

-#else

-Word16 sub(Word16 var1, Word16 var2);

-#endif

-

-/* Short division,       18  */

-#if (DIV_S_IS_INLINE)

-__inline Word16 div_s (Word16 var1, Word16 var2);

-#else

-Word16 div_s (Word16 var1, Word16 var2);

-#endif

-

-/* Short mult,          1   */

-#if (MULT_IS_INLINE)

-__inline Word16 mult (Word16 var1, Word16 var2);

-#else

-Word16 mult (Word16 var1, Word16 var2);

-#endif

-

-/* Short norm,           15  */

-#if (NORM_S_IS_INLINE)

-__inline Word16 norm_s (Word16 var1);

-#else

-Word16 norm_s (Word16 var1);

-#endif

-

-/* Long norm,            30  */

-#if (NORM_L_IS_INLINE)

-__inline Word16 norm_l (Word32 L_var1);

-#else

-Word16 norm_l (Word32 L_var1);

-#endif

-

-/* Round,               1   */

-#if (ROUND_IS_INLINE)

-__inline Word16 round16(Word32 L_var1);

-#else

-Word16 round16(Word32 L_var1);

-#endif

-

-/* Mac,  1  */

-#if (L_MAC_IS_INLINE)

-__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);

-#else

-Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);

-#endif

-

-#if (L_ADD_IS_INLINE)

-__inline Word32 L_add (Word32 L_var1, Word32 L_var2);

-#else

-Word32 L_add (Word32 L_var1, Word32 L_var2);

-#endif

-

-/* Extract high,        1   */

-#if (EXTRACT_H_IS_INLINE)

-__inline Word16 extract_h (Word32 L_var1);

-#else

-Word16 extract_h (Word32 L_var1);

-#endif

-

-/* Extract low,         1   */

-#if (EXTRACT_L_IS_INLINE)

-__inline Word16 extract_l(Word32 L_var1);

-#else

-Word16 extract_l(Word32 L_var1);

-#endif

-

-/* Mult with round, 2 */

-#if (MULT_R_IS_INLINE)

-__inline Word16 mult_r(Word16 var1, Word16 var2);

-#else

-Word16 mult_r(Word16 var1, Word16 var2);

-#endif

-

-/* Shift right with round, 2           */

-#if (SHR_R_IS_INLINE)

-__inline Word16 shr_r (Word16 var1, Word16 var2);

-#else

-Word16 shr_r (Word16 var1, Word16 var2);

-#endif

-

-/* Mac with rounding,2 */

-#if (MAC_R_IS_INLINE)

-__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);

-#else

-Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);

-#endif

-

-/* Msu with rounding,2 */

-#if (MSU_R_IS_INLINE)

-__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);

-#else

-Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);

-#endif

-

-/* Long shift right with round,  3             */

-#if (L_SHR_R_IS_INLINE)

-__inline Word32 L_shr_r (Word32 L_var1, Word16 var2);

-#else

-Word32 L_shr_r (Word32 L_var1, Word16 var2);

-#endif

-

-#if ARMV4_INASM

-__inline Word32 ASM_L_shr(Word32 L_var1, Word16 var2)

-{

-	Word32 result; 

-	asm volatile( 

-		"MOV %[result], %[L_var1], ASR %[var2] \n" 

-		:[result]"=r"(result)

-		:[L_var1]"r"(L_var1), [var2]"r"(var2)

-		); 

-	return result;	

-}

- 

-__inline Word32 ASM_L_shl(Word32 L_var1, Word16 var2)

-{

-	Word32 result; 

-	asm volatile( 

-		"MOV	r2, %[L_var1] \n"

-		"MOV	r3, #0x7fffffff\n"

-		"MOV	%[result], %[L_var1], ASL %[var2] \n" 

-		"TEQ	r2, %[result], ASR %[var2]\n"

-		"EORNE  %[result],r3,r2,ASR#31\n"

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1), [var2]"r"(var2)

-		:"r2", "r3"

-		); 

-	return result;	

-}

-

-__inline Word32 ASM_shr(Word32 L_var1, Word16 var2)

-{

-	Word32 result; 

-	asm volatile( 

-		"CMP	%[var2], #15\n"

-		"MOVGE  %[var2], #15\n"

-		"MOV	%[result], %[L_var1], ASR %[var2]\n"

-		:[result]"=r"(result)

-		:[L_var1]"r"(L_var1), [var2]"r"(var2) 

-		); 

-	return result;	

-} 

-

-__inline Word32 ASM_shl(Word32 L_var1, Word16 var2)

-{

-	Word32 result; 

-	asm volatile( 

-		"CMP	%[var2], #16\n"

-		"MOVGE  %[var2], #16\n"

-		"MOV    %[result], %[L_var1], ASL %[var2]\n"

-		"MOV    r3, #1\n"

-        "MOV    r2, %[result], ASR #15\n"

-        "RSB    r3,r3,r3,LSL #15 \n"

-        "TEQ    r2, %[result], ASR #31 \n"

-        "EORNE  %[result], r3, %[result],ASR #31"

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1), [var2]"r"(var2)

-		:"r2", "r3"

-		); 

-	return result;	

-} 

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   definitions for inline basic arithmetic operators                       |

- |___________________________________________________________________________|

-*/

-#if (SATRUATE_IS_INLINE)

-__inline Word16 saturate(Word32 L_var1)

-{

-#if ARMV5TE_SAT

-	Word16 result;

-	asm volatile (

-		"MOV	%[result], %[L_var1]\n"

-		"MOV	r3, #1\n"

-		"MOV	r2,%[L_var1],ASR#15\n"

-		"RSB	r3, r3, r3, LSL #15\n"

-		"TEQ	r2,%[L_var1],ASR#31\n"	

-		"EORNE	%[result],r3,%[L_var1],ASR#31\n"

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1)

-		:"r2", "r3"			

-	);

-

-	return result;

-#else

-    Word16 var_out;

-    

-    //var_out = (L_var1 > (Word32)0X00007fffL) ? (MAX_16) : ((L_var1 < (Word32)0xffff8000L) ? (MIN_16) : ((Word16)L_var1));

-

-    if (L_var1 > 0X00007fffL)

-    {

-        var_out = MAX_16;

-    }

-    else if (L_var1 < (Word32) 0xffff8000L)

-    {

-        var_out = MIN_16;

-    }

-    else

-    {

-        var_out = extract_l(L_var1);

-    }

-

-    return (var_out);

-#endif

-}

-#endif

-

-/* Short shift left,    1   */

-#if (SHL_IS_INLINE)

-__inline Word16 shl (Word16 var1, Word16 var2)

-{

-#if ARMV5TE_SHL

-	if(var2>=0)

-	{

-		return ASM_shl( var1, var2);

-	}

-	else

-	{

-		return ASM_shr( var1, -var2);

-	}

-#else

-    Word16 var_out;

-    Word32 result;

-

-    if (var2 < 0)

-    {

-        var_out = shr (var1, (Word16)-var2);

-    }

-    else

-    {

-        result = (Word32) var1 *((Word32) 1 << var2);

-

-        if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))

-        {

-            var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);

-        }

-        else

-        {

-            var_out = extract_l(result);

-        }

-    }

-    return (var_out);

-#endif

-}

-#endif

-

-/* Short shift right,   1   */

-#if (SHR_IS_INLINE)

-__inline Word16 shr (Word16 var1, Word16 var2)

-{

-#if ARMV5TE_SHR

-	if(var2>=0)

-	{

-		return  ASM_shr( var1, var2);

-	}

-	else

-	{

-		return  ASM_shl( var1, -var2);

-	}

-#else

-    Word16 var_out;

-

-    if (var2 < 0)

-    {

-        var_out = shl (var1, (Word16)-var2);

-    }

-    else

-    {

-        if (var2 >= 15)

-        {

-            var_out = (Word16)((var1 < 0) ? -1 : 0);

-        }

-        else

-        {

-            if (var1 < 0)

-            {

-                var_out = (Word16)(~((~var1) >> var2));

-            }

-            else

-            {

-                var_out = (Word16)(var1 >> var2);

-            }

-        }

-    }

-

-    return (var_out);

-#endif

-}

-#endif

-

-

-#if (L_MULT_IS_INLINE)

-__inline Word32 L_mult(Word16 var1, Word16 var2)

-{

-#if ARMV5TE_L_MULT

-	Word32 result; 

-	asm volatile( 

-		"SMULBB %[result], %[var1], %[var2] \n" 

-		"QADD %[result], %[result], %[result] \n" 

-		:[result]"+r"(result)

-		:[var1]"r"(var1), [var2]"r"(var2)

-		); 

-	return result;

-#else

-    Word32 L_var_out;

-

-    L_var_out = (Word32) var1 *(Word32) var2;

-

-    if (L_var_out != (Word32) 0x40000000L)

-    {

-        L_var_out <<= 1;

-    }

-    else

-    {

-        L_var_out = MAX_32;

-    }

-    return (L_var_out);

-#endif

-}

-#endif

-

-#if (L_MSU_IS_INLINE)

-__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)

-{

-#if ARMV5TE_L_MSU

-	Word32 result; 

-	asm volatile( 

-		"SMULBB %[result], %[var1], %[var2] \n" 

-		"QADD %[result], %[result], %[result] \n"

-		"QSUB %[result], %[L_var3], %[result]\n"

-		:[result]"+r"(result)

-		:[L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)

-		); 

-	return result;

-#else

-    Word32 L_var_out;

-    Word32 L_product;

-

-    L_product = L_mult(var1, var2);

-    L_var_out = L_sub(L_var3, L_product);

-    return (L_var_out);

-#endif

-}

-#endif

-

-#if (L_SUB_IS_INLINE)

-__inline Word32 L_sub(Word32 L_var1, Word32 L_var2)

-{

-#if ARMV5TE_L_SUB

-	Word32 result; 

-	asm volatile( 

-		"QSUB %[result], %[L_var1], %[L_var2]\n"

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)

-		); 

-	return result;

-#else

-    Word32 L_var_out;

-

-    L_var_out = L_var1 - L_var2;

-

-    if (((L_var1 ^ L_var2) & MIN_32) != 0)

-    {

-        if ((L_var_out ^ L_var1) & MIN_32)

-        {

-            L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;

-        }

-    }

-

-    return (L_var_out);

-#endif

-}

-#endif

-

-#if (L_SHL_IS_INLINE)

-__inline Word32 L_shl(Word32 L_var1, Word16 var2)

-{

-#if ARMV5TE_L_SHL

-    if(var2>=0)

-    {

-        return  ASM_L_shl( L_var1, var2);

-    }

-    else

-    {

-        return  ASM_L_shr( L_var1, -var2);

-    }

-#else

-    Word32 L_var_out = 0L;

-

-    if (var2 <= 0)

-    {

-        L_var1 = L_shr(L_var1, (Word16)-var2);

-    }

-    else

-    {

-        for (; var2 > 0; var2--)

-        {

-            if (L_var1 > (Word32) 0X3fffffffL)

-            {

-                return MAX_32;

-            }

-            else

-            {

-                if (L_var1 < (Word32) 0xc0000000L)

-                {

-                    return MIN_32;

-                }

-            }

-            L_var1 <<= 1;

-            L_var_out = L_var1;

-        }

-    }

-    return (L_var1);

-#endif

-}

-#endif

-

-#if (L_SHR_IS_INLINE)

-__inline Word32 L_shr (Word32 L_var1, Word16 var2)

-{

-#if ARMV5TE_L_SHR

-	if(var2>=0)

-	{

-		return ASM_L_shr( L_var1, var2);

-	}

-	else

-	{

-		return ASM_L_shl( L_var1, -var2);

-	}

-#else

-    Word32 L_var_out;

-

-    if (var2 < 0)

-    {

-        L_var_out = L_shl (L_var1, (Word16)-var2);

-    }

-    else

-    {

-        if (var2 >= 31)

-        {

-            L_var_out = (L_var1 < 0L) ? -1 : 0;

-        }

-        else

-        {

-            if (L_var1 < 0)

-            {

-                L_var_out = ~((~L_var1) >> var2);

-            }

-            else

-            {

-                L_var_out = L_var1 >> var2;

-            }

-        }

-    }

-    return (L_var_out);

-#endif

-}

-#endif

-

-/* Short add,           1   */

-#if (ADD_IS_INLINE)

-__inline Word16 add (Word16 var1, Word16 var2)

-{

-#if ARMV5TE_ADD

-	Word32 result; 

-	asm volatile( 

-		"ADD  %[result], %[var1], %[var2] \n" 

-		"MOV  r3, #0x1\n"

-		"MOV  r2, %[result], ASR #15\n"

-		"RSB  r3, r3, r3, LSL, #15\n"

-		"TEQ  r2, %[result], ASR #31\n"

-		"EORNE %[result], r3, %[result], ASR #31"

-		:[result]"+r"(result)

-		:[var1]"r"(var1), [var2]"r"(var2)

-		:"r2", "r3"

-		); 

-	return result;

-#else

-    Word16 var_out;

-    Word32 L_sum;

-

-    L_sum = (Word32) var1 + var2;

-    var_out = saturate(L_sum);

-

-    return (var_out);

-#endif

-}

-#endif

-

-/* Short sub,           1   */

-#if (SUB_IS_INLINE)

-__inline Word16 sub(Word16 var1, Word16 var2)

-{

-#if ARMV5TE_SUB

-	Word32 result; 

-	asm volatile( 

-		"MOV   r3, #1\n"

-		"SUB   %[result], %[var1], %[var2] \n"		

-		"RSB   r3,r3,r3,LSL#15\n"

-		"MOV   r2, %[var1], ASR #15 \n" 

-		"TEQ   r2, %[var1], ASR #31 \n"

-		"EORNE %[result], r3, %[result], ASR #31 \n"

-		:[result]"+r"(result)

-		:[var1]"r"(var1), [var2]"r"(var2)

-		:"r2", "r3"

-		); 

-	return result;

-#else

-    Word16 var_out;

-    Word32 L_diff;

-

-    L_diff = (Word32) var1 - var2;

-    var_out = saturate(L_diff);

-   

-    return (var_out);

-#endif

-}

-#endif

-

-/* Short division,       18  */

-#if (DIV_S_IS_INLINE)

-__inline Word16 div_s (Word16 var1, Word16 var2)

-{

-    Word16 var_out = 0;

-    Word16 iteration;

-    Word32 L_num;

-    Word32 L_denom;

-

-    var_out = MAX_16;

-    if (var1!= var2)//var1!= var2

-    {

-    	var_out = 0;

-    	L_num = (Word32) var1;

-    

-    	L_denom = (Word32) var2;

-    	

-		//return (L_num<<15)/var2;

-

-    	for (iteration = 0; iteration < 15; iteration++)

-    	{

-    		var_out <<= 1;

-    		L_num <<= 1;

-    		

-    		if (L_num >= L_denom)

-    		{

-    			L_num -= L_denom;

-    			var_out++;

-    		}

-    	}

-    }

-    return (var_out);

-}

-#endif

-

-/* Short mult,          1   */

-#if (MULT_IS_INLINE)

-__inline Word16 mult (Word16 var1, Word16 var2)

-{

-#if ARMV5TE_MULT

-	Word32 result; 

-	asm volatile( 

-		"SMULBB r2, %[var1], %[var2] \n"

-		"MOV	r3, #1\n"

-		"MOV	%[result], r2, ASR #15\n"

-		"RSB	r3, r3, r3, LSL #15\n"

-		"MOV	r2, %[result], ASR #15\n"

-		"TEQ	r2, %[result], ASR #31\n"

-		"EORNE  %[result], r3, %[result], ASR #31 \n"

-		:[result]"+r"(result)

-		:[var1]"r"(var1), [var2]"r"(var2)

-		:"r2", "r3"

-		); 

-	return result;

-#else

-    Word16 var_out;

-    Word32 L_product;

-

-    L_product = (Word32) var1 *(Word32) var2;

-    L_product = (L_product & (Word32) 0xffff8000L) >> 15;

-    if (L_product & (Word32) 0x00010000L)

-        L_product = L_product | (Word32) 0xffff0000L;

-    var_out = saturate(L_product);

-

-    return (var_out);

-#endif

-}

-#endif

-

-

-/* Short norm,           15  */

-#if (NORM_S_IS_INLINE)

-__inline Word16 norm_s (Word16 var1)

-{

-#if ARMV5TE_NORM_S

-	Word16 result; 

-	asm volatile( 

-		"MOV   r2,%[var1] \n"

-		"CMP   r2, #0\n"

-		"RSBLT %[var1], %[var1], #0 \n"

-		"CLZNE %[result], %[var1]\n"

-		"SUBNE %[result], %[result], #17\n"

-		"MOVEQ %[result], #0\n"

-		"CMP   r2, #-1\n"

-		"MOVEQ %[result], #15\n" 

-		:[result]"+r"(result)

-		:[var1]"r"(var1)

-		:"r2"

-		); 

-	return result;

-#else

-    Word16 var_out;

-

-    if (var1 == 0)

-    {

-        var_out = 0;

-    }

-    else

-    {

-        if (var1 == -1)

-        {

-            var_out = 15;

-        }

-        else

-        {

-            if (var1 < 0)

-            {

-                var1 = (Word16)~var1;

-            }

-            for (var_out = 0; var1 < 0x4000; var_out++)

-            {

-                var1 <<= 1;

-            }

-        }

-    }

-    return (var_out);

-#endif

-}

-#endif

-

-/* Long norm,            30  */

-#if (NORM_L_IS_INLINE)

-__inline Word16 norm_l (Word32 L_var1)

-{

-#if ARMV5TE_NORM_L

-	Word16 result; 

-	asm volatile( 

-		"CMP    %[L_var1], #0\n"

-		"CLZNE  %[result], %[L_var1]\n"

-		"SUBNE  %[result], %[result], #1\n" 

-		"MOVEQ  %[result], #0\n"

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1)

-		); 

-	return result;

-#else

-    //Word16 var_out;

-

-    //if (L_var1 == 0)

-    //{

-    //    var_out = 0;

-    //}

-    //else

-    //{

-    //    if (L_var1 == (Word32) 0xffffffffL)

-    //    {

-    //        var_out = 31;

-    //    }

-    //    else

-    //    {

-    //        if (L_var1 < 0)

-    //        {

-    //            L_var1 = ~L_var1;

-    //        }

-    //        for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)

-    //        {

-    //            L_var1 <<= 1;

-    //        }

-    //    }

-    //}

-    //return (var_out);

-  Word16 a16;

-  Word16 r = 0 ;       

-

-   

-  if ( L_var1 < 0 ) {

-    L_var1 = ~L_var1; 

-  }

-

-  if (0 == (L_var1 & 0x7fff8000)) {

-    a16 = extract_l(L_var1);

-    r += 16;

-       

-    if (0 == (a16 & 0x7f80)) {

-      r += 8;

-         

-      if (0 == (a16 & 0x0078)) {

-        r += 4;

-           

-        if (0 == (a16 & 0x0006)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x0001)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x0004)) {

-            r += 1;

-          }

-        }

-      }

-      else {

-           

-        if (0 == (a16 & 0x0060)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x0010)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x0040)) {

-            r += 1;

-          }

-        }

-      }

-    } 

-    else { 

-         

-      if (0 == (a16 & 0x7800)) {

-        r += 4;

-           

-        if (0 == (a16 & 0x0600)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x0100)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x0400)) {

-            r += 1;

-          }

-        }

-      }

-      else {

-           

-        if (0 == (a16 & 0x6000)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x1000)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x4000)) {

-            r += 1;

-          }

-        }

-      }

-    }

-  }

-  else {

-    a16 = extract_h(L_var1);

-       

-    if (0 == (a16 & 0x7f80)) {

-      r += 8;

-         

-      if (0 == (a16 & 0x0078)) {

-        r += 4 ;

-           

-        if (0 == (a16 & 0x0006)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x0001)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x0004)) {

-            r += 1;

-          }

-        }

-      }

-      else {

-           

-        if (0 == (a16 & 0x0060)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x0010)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x0040)) {

-            r += 1;

-          }

-        }

-      }

-    }

-    else {

-         

-      if (0 == (a16 & 0x7800)) {

-        r += 4;

-           

-        if (0 == (a16 & 0x0600)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x0100)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x0400)) {

-            r += 1;

-          }

-        }

-      }

-      else {

-           

-        if (0 == (a16 & 0x6000)) {

-          r += 2;

-             

-          if (0 == (a16 & 0x1000)) {

-            r += 1;

-          }

-        }

-        else {

-             

-          if (0 == (a16 & 0x4000)) {

-            return 1;

-          }

-        }

-      }

-    }

-  }

-  

-  return r ;

-#endif

-}

-#endif

-

-/* Round,               1   */

-#if (ROUND_IS_INLINE)

-__inline Word16 round16(Word32 L_var1)

-{

-#if ARMV5TE_ROUND

-	Word16 result; 

-	asm volatile( 

-		"MOV   r1,#0x00008000\n"

-		"QADD  %[result], %[L_var1], r1\n"

-		"MOV   %[result], %[result], ASR #16 \n" 

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1)

-		:"r1"

-		); 

-	return result;

-#else   

-    Word16 var_out;

-    Word32 L_rounded;

-

-    L_rounded = L_add (L_var1, (Word32) 0x00008000L);

-    var_out = extract_h (L_rounded);

-    return (var_out);

-#endif

-}

-#endif

-

-/* Mac,  1  */

-#if (L_MAC_IS_INLINE)

-__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)

-{

-#if ARMV5TE_L_MAC

-	Word32 result; 

-	asm volatile( 

-		"SMULBB %[result], %[var1], %[var2]\n"

-		"QADD	%[result], %[result], %[result]\n"

-		"QADD   %[result], %[result], %[L_var3]\n"

-		:[result]"+r"(result)

-		: [L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)

-		); 

-	return result;

-#else

-    Word32 L_var_out;

-    Word32 L_product;

-

-    L_product = L_mult(var1, var2);

-    L_var_out = L_add (L_var3, L_product);

-    return (L_var_out);

-#endif

-}

-#endif

-

-#if (L_ADD_IS_INLINE)

-__inline Word32 L_add (Word32 L_var1, Word32 L_var2)

-{

-#if ARMV5TE_L_ADD

-	Word32 result; 

-	asm volatile( 

-		"QADD %[result], %[L_var1], %[L_var2]\n"

-		:[result]"+r"(result)

-		:[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)

-		); 

-	return result;

-#else

-    Word32 L_var_out;

-

-    L_var_out = L_var1 + L_var2;

-    if (((L_var1 ^ L_var2) & MIN_32) == 0)

-    {

-        if ((L_var_out ^ L_var1) & MIN_32)

-        {

-            L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;

-        }

-    }

-    return (L_var_out);

-#endif

-}

-#endif

-

-

-

-#if (MULT_R_IS_INLINE)

-__inline Word16 mult_r (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-    Word32 L_product_arr;

-

-    L_product_arr = (Word32)var1 *(Word32)var2;       /* product */

-    L_product_arr += (Word32)0x00004000L;      /* round */

-    L_product_arr >>= 15;       /* shift */

-

-    var_out = saturate(L_product_arr);

-

-    return (var_out);

-}

-#endif

-

-#if (SHR_R_IS_INLINE)

-__inline Word16 shr_r (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    if (var2 > 15)

-    {

-        var_out = 0;

-    }

-    else

-    {

-        var_out = shr(var1, var2);

-

-        if (var2 > 0)

-        {

-            if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)

-            {

-                var_out++;

-            }

-        }

-    }

-

-    return (var_out);

-}

-#endif

-

-#if (MAC_R_IS_INLINE)

-__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    L_var3 = L_mac (L_var3, var1, var2);

-    var_out = (Word16)((L_var3 + 0x8000L) >> 16);

-

-    return (var_out);

-}

-#endif

-

-#if (MSU_R_IS_INLINE)

-__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    L_var3 = L_msu (L_var3, var1, var2);

-    var_out = (Word16)((L_var3 + 0x8000L) >> 16);

-    

-    return (var_out);

-}

-#endif

-

-#if (L_SHR_R_IS_INLINE)

-__inline Word32 L_shr_r (Word32 L_var1, Word16 var2)

-{

-    Word32 L_var_out;

-

-    if (var2 > 31)

-    {

-        L_var_out = 0;

-    }

-    else

-    {

-        L_var_out = L_shr(L_var1, var2);

-

-        if (var2 > 0)

-        {

-            if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)

-            {

-                L_var_out++;

-            }

-        }

-    }

-

-    return (L_var_out);

-}

-#endif

-

-#if (EXTRACT_H_IS_INLINE)

-__inline Word16 extract_h (Word32 L_var1)

-{

-    Word16 var_out;

-

-    var_out = (Word16) (L_var1 >> 16);

-

-    return (var_out);

-}

-#endif

-

-#if (EXTRACT_L_IS_INLINE)

-__inline Word16 extract_l(Word32 L_var1)

-{

-	return (Word16) L_var1;

-}

-#endif

-

+#define ABS(a)	((a) >= 0) ? (a) : (-(a))
+
+/* Short abs,           1   */
+#define abs_s(x)       ((Word16)(((x) != MIN_16) ? (((x) >= 0) ? (x) : (-(x))) : MAX_16))
+
+/* 16 bit var1 -> MSB,     2 */
+#define L_deposit_h(x) (((Word32)(x)) << 16)
+
+
+/* 16 bit var1 -> LSB,     2 */
+#define L_deposit_l(x) ((Word32)(x))
+
+
+/* Long abs,              3  */
+#define L_abs(x) (((x) != MIN_32) ? (((x) >= 0) ? (x) : (-(x))) : MAX_32)
+
+
+/* Short negate,        1   */
+#define negate(var1) ((Word16)(((var1) == MIN_16) ? MAX_16 : (-(var1))))
+
+
+/* Long negate,     2 */
+#define L_negate(L_var1) (((L_var1) == (MIN_32)) ? (MAX_32) : (-(L_var1)))
+
+
+#define MULHIGH(A,B) (int)(((Word64)(A)*(Word64)(B)) >> 32)
+#define fixmul(a, b) (int)((((Word64)(a)*(Word64)(b)) >> 32) << 1)
+
+
+#if  (SATRUATE_IS_INLINE)
+__inline Word16 saturate(Word32 L_var1);
+#else
+Word16 saturate(Word32 L_var1);
+#endif
+
+/* Short shift left,    1   */
+#if (SHL_IS_INLINE)
+__inline Word16 shl (Word16 var1, Word16 var2);
+#else
+Word16 shl (Word16 var1, Word16 var2);
+#endif
+
+/* Short shift right,   1   */
+#if (SHR_IS_INLINE)
+__inline Word16 shr (Word16 var1, Word16 var2);
+#else
+Word16 shr (Word16 var1, Word16 var2);
+#endif
+
+#if (L_MULT_IS_INLINE)
+__inline Word32 L_mult(Word16 var1, Word16 var2);
+#else
+Word32 L_mult(Word16 var1, Word16 var2);
+#endif
+
+/* Msu,  1  */
+#if (L_MSU_IS_INLINE)
+__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+    
+/* Long sub,        2 */
+#if (L_SUB_IS_INLINE)
+__inline Word32 L_sub(Word32 L_var1, Word32 L_var2);
+#else
+Word32 L_sub(Word32 L_var1, Word32 L_var2);
+#endif
+
+/* Long shift left, 2 */
+#if (L_SHL_IS_INLINE)
+__inline Word32 L_shl (Word32 L_var1, Word16 var2);
+#else
+Word32 L_shl (Word32 L_var1, Word16 var2);
+#endif
+
+/* Long shift right, 2*/
+#if (L_SHR_IS_INLINE)
+__inline Word32 L_shr (Word32 L_var1, Word16 var2);
+#else
+Word32 L_shr (Word32 L_var1, Word16 var2);
+#endif
+
+/* Short add,           1   */
+#if (ADD_IS_INLINE)
+__inline Word16 add (Word16 var1, Word16 var2);
+#else
+Word16 add (Word16 var1, Word16 var2);
+#endif
+    
+/* Short sub,           1   */
+#if (SUB_IS_INLINE)
+__inline Word16 sub(Word16 var1, Word16 var2);
+#else
+Word16 sub(Word16 var1, Word16 var2);
+#endif
+
+/* Short division,       18  */
+#if (DIV_S_IS_INLINE)
+__inline Word16 div_s (Word16 var1, Word16 var2);
+#else
+Word16 div_s (Word16 var1, Word16 var2);
+#endif
+
+/* Short mult,          1   */
+#if (MULT_IS_INLINE)
+__inline Word16 mult (Word16 var1, Word16 var2);
+#else
+Word16 mult (Word16 var1, Word16 var2);
+#endif
+
+/* Short norm,           15  */
+#if (NORM_S_IS_INLINE)
+__inline Word16 norm_s (Word16 var1);
+#else
+Word16 norm_s (Word16 var1);
+#endif
+
+/* Long norm,            30  */
+#if (NORM_L_IS_INLINE)
+__inline Word16 norm_l (Word32 L_var1);
+#else
+Word16 norm_l (Word32 L_var1);
+#endif
+
+/* Round,               1   */
+#if (ROUND_IS_INLINE)
+__inline Word16 round16(Word32 L_var1);
+#else
+Word16 round16(Word32 L_var1);
+#endif
+
+/* Mac,  1  */
+#if (L_MAC_IS_INLINE)
+__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+#if (L_ADD_IS_INLINE)
+__inline Word32 L_add (Word32 L_var1, Word32 L_var2);
+#else
+Word32 L_add (Word32 L_var1, Word32 L_var2);
+#endif
+
+/* Extract high,        1   */
+#if (EXTRACT_H_IS_INLINE)
+__inline Word16 extract_h (Word32 L_var1);
+#else
+Word16 extract_h (Word32 L_var1);
+#endif
+
+/* Extract low,         1   */
+#if (EXTRACT_L_IS_INLINE)
+__inline Word16 extract_l(Word32 L_var1);
+#else
+Word16 extract_l(Word32 L_var1);
+#endif
+
+/* Mult with round, 2 */
+#if (MULT_R_IS_INLINE)
+__inline Word16 mult_r(Word16 var1, Word16 var2);
+#else
+Word16 mult_r(Word16 var1, Word16 var2);
+#endif
+
+/* Shift right with round, 2           */
+#if (SHR_R_IS_INLINE)
+__inline Word16 shr_r (Word16 var1, Word16 var2);
+#else
+Word16 shr_r (Word16 var1, Word16 var2);
+#endif
+
+/* Mac with rounding,2 */
+#if (MAC_R_IS_INLINE)
+__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+/* Msu with rounding,2 */
+#if (MSU_R_IS_INLINE)
+__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+/* Long shift right with round,  3             */
+#if (L_SHR_R_IS_INLINE)
+__inline Word32 L_shr_r (Word32 L_var1, Word16 var2);
+#else
+Word32 L_shr_r (Word32 L_var1, Word16 var2);
+#endif
+
+#if ARMV4_INASM
+__inline Word32 ASM_L_shr(Word32 L_var1, Word16 var2)
+{
+	Word32 result; 
+	asm volatile( 
+		"MOV %[result], %[L_var1], ASR %[var2] \n" 
+		:[result]"=r"(result)
+		:[L_var1]"r"(L_var1), [var2]"r"(var2)
+		); 
+	return result;	
+}
+ 
+__inline Word32 ASM_L_shl(Word32 L_var1, Word16 var2)
+{
+	Word32 result; 
+	asm volatile( 
+		"MOV	r2, %[L_var1] \n"
+		"MOV	r3, #0x7fffffff\n"
+		"MOV	%[result], %[L_var1], ASL %[var2] \n" 
+		"TEQ	r2, %[result], ASR %[var2]\n"
+		"EORNE  %[result],r3,r2,ASR#31\n"
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1), [var2]"r"(var2)
+		:"r2", "r3"
+		); 
+	return result;	
+}
+
+__inline Word32 ASM_shr(Word32 L_var1, Word16 var2)
+{
+	Word32 result; 
+	asm volatile( 
+		"CMP	%[var2], #15\n"
+		"MOVGE  %[var2], #15\n"
+		"MOV	%[result], %[L_var1], ASR %[var2]\n"
+		:[result]"=r"(result)
+		:[L_var1]"r"(L_var1), [var2]"r"(var2) 
+		); 
+	return result;	
+} 
+
+__inline Word32 ASM_shl(Word32 L_var1, Word16 var2)
+{
+	Word32 result; 
+	asm volatile( 
+		"CMP	%[var2], #16\n"
+		"MOVGE  %[var2], #16\n"
+		"MOV    %[result], %[L_var1], ASL %[var2]\n"
+		"MOV    r3, #1\n"
+        "MOV    r2, %[result], ASR #15\n"
+        "RSB    r3,r3,r3,LSL #15 \n"
+        "TEQ    r2, %[result], ASR #31 \n"
+        "EORNE  %[result], r3, %[result],ASR #31"
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1), [var2]"r"(var2)
+		:"r2", "r3"
+		); 
+	return result;	
+} 
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   definitions for inline basic arithmetic operators                       |
+ |___________________________________________________________________________|
+*/
+#if (SATRUATE_IS_INLINE)
+__inline Word16 saturate(Word32 L_var1)
+{
+#if ARMV5TE_SAT
+	Word16 result;
+	asm volatile (
+		"MOV	%[result], %[L_var1]\n"
+		"MOV	r3, #1\n"
+		"MOV	r2,%[L_var1],ASR#15\n"
+		"RSB	r3, r3, r3, LSL #15\n"
+		"TEQ	r2,%[L_var1],ASR#31\n"	
+		"EORNE	%[result],r3,%[L_var1],ASR#31\n"
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1)
+		:"r2", "r3"			
+	);
+
+	return result;
+#else
+    Word16 var_out;
+    
+    //var_out = (L_var1 > (Word32)0X00007fffL) ? (MAX_16) : ((L_var1 < (Word32)0xffff8000L) ? (MIN_16) : ((Word16)L_var1));
+
+    if (L_var1 > 0X00007fffL)
+    {
+        var_out = MAX_16;
+    }
+    else if (L_var1 < (Word32) 0xffff8000L)
+    {
+        var_out = MIN_16;
+    }
+    else
+    {
+        var_out = extract_l(L_var1);
+    }
+
+    return (var_out);
+#endif
+}
+#endif
+
+/* Short shift left,    1   */
+#if (SHL_IS_INLINE)
+__inline Word16 shl (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_SHL
+	if(var2>=0)
+	{
+		return ASM_shl( var1, var2);
+	}
+	else
+	{
+		return ASM_shr( var1, -var2);
+	}
+#else
+    Word16 var_out;
+    Word32 result;
+
+    if (var2 < 0)
+    {
+        var_out = shr (var1, (Word16)-var2);
+    }
+    else
+    {
+        result = (Word32) var1 *((Word32) 1 << var2);
+
+        if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
+        {
+            var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
+        }
+        else
+        {
+            var_out = extract_l(result);
+        }
+    }
+    return (var_out);
+#endif
+}
+#endif
+
+/* Short shift right,   1   */
+#if (SHR_IS_INLINE)
+__inline Word16 shr (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_SHR
+	if(var2>=0)
+	{
+		return  ASM_shr( var1, var2);
+	}
+	else
+	{
+		return  ASM_shl( var1, -var2);
+	}
+#else
+    Word16 var_out;
+
+    if (var2 < 0)
+    {
+        var_out = shl (var1, (Word16)-var2);
+    }
+    else
+    {
+        if (var2 >= 15)
+        {
+            var_out = (Word16)((var1 < 0) ? -1 : 0);
+        }
+        else
+        {
+            if (var1 < 0)
+            {
+                var_out = (Word16)(~((~var1) >> var2));
+            }
+            else
+            {
+                var_out = (Word16)(var1 >> var2);
+            }
+        }
+    }
+
+    return (var_out);
+#endif
+}
+#endif
+
+
+#if (L_MULT_IS_INLINE)
+__inline Word32 L_mult(Word16 var1, Word16 var2)
+{
+#if ARMV5TE_L_MULT
+	Word32 result; 
+	asm volatile( 
+		"SMULBB %[result], %[var1], %[var2] \n" 
+		"QADD %[result], %[result], %[result] \n" 
+		:[result]"+r"(result)
+		:[var1]"r"(var1), [var2]"r"(var2)
+		); 
+	return result;
+#else
+    Word32 L_var_out;
+
+    L_var_out = (Word32) var1 *(Word32) var2;
+
+    if (L_var_out != (Word32) 0x40000000L)
+    {
+        L_var_out <<= 1;
+    }
+    else
+    {
+        L_var_out = MAX_32;
+    }
+    return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_MSU_IS_INLINE)
+__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
+{
+#if ARMV5TE_L_MSU
+	Word32 result; 
+	asm volatile( 
+		"SMULBB %[result], %[var1], %[var2] \n" 
+		"QADD %[result], %[result], %[result] \n"
+		"QSUB %[result], %[L_var3], %[result]\n"
+		:[result]"+r"(result)
+		:[L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)
+		); 
+	return result;
+#else
+    Word32 L_var_out;
+    Word32 L_product;
+
+    L_product = L_mult(var1, var2);
+    L_var_out = L_sub(L_var3, L_product);
+    return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_SUB_IS_INLINE)
+__inline Word32 L_sub(Word32 L_var1, Word32 L_var2)
+{
+#if ARMV5TE_L_SUB
+	Word32 result; 
+	asm volatile( 
+		"QSUB %[result], %[L_var1], %[L_var2]\n"
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)
+		); 
+	return result;
+#else
+    Word32 L_var_out;
+
+    L_var_out = L_var1 - L_var2;
+
+    if (((L_var1 ^ L_var2) & MIN_32) != 0)
+    {
+        if ((L_var_out ^ L_var1) & MIN_32)
+        {
+            L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
+        }
+    }
+
+    return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_SHL_IS_INLINE)
+__inline Word32 L_shl(Word32 L_var1, Word16 var2)
+{
+#if ARMV5TE_L_SHL
+    if(var2>=0)
+    {
+        return  ASM_L_shl( L_var1, var2);
+    }
+    else
+    {
+        return  ASM_L_shr( L_var1, -var2);
+    }
+#else
+    Word32 L_var_out = 0L;
+
+    if (var2 <= 0)
+    {
+        L_var1 = L_shr(L_var1, (Word16)-var2);
+    }
+    else
+    {
+        for (; var2 > 0; var2--)
+        {
+            if (L_var1 > (Word32) 0X3fffffffL)
+            {
+                return MAX_32;
+            }
+            else
+            {
+                if (L_var1 < (Word32) 0xc0000000L)
+                {
+                    return MIN_32;
+                }
+            }
+            L_var1 <<= 1;
+            L_var_out = L_var1;
+        }
+    }
+    return (L_var1);
+#endif
+}
+#endif
+
+#if (L_SHR_IS_INLINE)
+__inline Word32 L_shr (Word32 L_var1, Word16 var2)
+{
+#if ARMV5TE_L_SHR
+	if(var2>=0)
+	{
+		return ASM_L_shr( L_var1, var2);
+	}
+	else
+	{
+		return ASM_L_shl( L_var1, -var2);
+	}
+#else
+    Word32 L_var_out;
+
+    if (var2 < 0)
+    {
+        L_var_out = L_shl (L_var1, (Word16)-var2);
+    }
+    else
+    {
+        if (var2 >= 31)
+        {
+            L_var_out = (L_var1 < 0L) ? -1 : 0;
+        }
+        else
+        {
+            if (L_var1 < 0)
+            {
+                L_var_out = ~((~L_var1) >> var2);
+            }
+            else
+            {
+                L_var_out = L_var1 >> var2;
+            }
+        }
+    }
+    return (L_var_out);
+#endif
+}
+#endif
+
+/* Short add,           1   */
+#if (ADD_IS_INLINE)
+__inline Word16 add (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_ADD
+	Word32 result; 
+	asm volatile( 
+		"ADD  %[result], %[var1], %[var2] \n" 
+		"MOV  r3, #0x1\n"
+		"MOV  r2, %[result], ASR #15\n"
+		"RSB  r3, r3, r3, LSL, #15\n"
+		"TEQ  r2, %[result], ASR #31\n"
+		"EORNE %[result], r3, %[result], ASR #31"
+		:[result]"+r"(result)
+		:[var1]"r"(var1), [var2]"r"(var2)
+		:"r2", "r3"
+		); 
+	return result;
+#else
+    Word16 var_out;
+    Word32 L_sum;
+
+    L_sum = (Word32) var1 + var2;
+    var_out = saturate(L_sum);
+
+    return (var_out);
+#endif
+}
+#endif
+
+/* Short sub,           1   */
+#if (SUB_IS_INLINE)
+__inline Word16 sub(Word16 var1, Word16 var2)
+{
+#if ARMV5TE_SUB
+	Word32 result; 
+	asm volatile( 
+		"MOV   r3, #1\n"
+		"SUB   %[result], %[var1], %[var2] \n"		
+		"RSB   r3,r3,r3,LSL#15\n"
+		"MOV   r2, %[var1], ASR #15 \n" 
+		"TEQ   r2, %[var1], ASR #31 \n"
+		"EORNE %[result], r3, %[result], ASR #31 \n"
+		:[result]"+r"(result)
+		:[var1]"r"(var1), [var2]"r"(var2)
+		:"r2", "r3"
+		); 
+	return result;
+#else
+    Word16 var_out;
+    Word32 L_diff;
+
+    L_diff = (Word32) var1 - var2;
+    var_out = saturate(L_diff);
+   
+    return (var_out);
+#endif
+}
+#endif
+
+/* Short division,       18  */
+#if (DIV_S_IS_INLINE)
+__inline Word16 div_s (Word16 var1, Word16 var2)
+{
+    Word16 var_out = 0;
+    Word16 iteration;
+    Word32 L_num;
+    Word32 L_denom;
+
+    var_out = MAX_16;
+    if (var1!= var2)//var1!= var2
+    {
+    	var_out = 0;
+    	L_num = (Word32) var1;
+    
+    	L_denom = (Word32) var2;
+    	
+		//return (L_num<<15)/var2;
+
+    	for (iteration = 0; iteration < 15; iteration++)
+    	{
+    		var_out <<= 1;
+    		L_num <<= 1;
+    		
+    		if (L_num >= L_denom)
+    		{
+    			L_num -= L_denom;
+    			var_out++;
+    		}
+    	}
+    }
+    return (var_out);
+}
+#endif
+
+/* Short mult,          1   */
+#if (MULT_IS_INLINE)
+__inline Word16 mult (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_MULT
+	Word32 result; 
+	asm volatile( 
+		"SMULBB r2, %[var1], %[var2] \n"
+		"MOV	r3, #1\n"
+		"MOV	%[result], r2, ASR #15\n"
+		"RSB	r3, r3, r3, LSL #15\n"
+		"MOV	r2, %[result], ASR #15\n"
+		"TEQ	r2, %[result], ASR #31\n"
+		"EORNE  %[result], r3, %[result], ASR #31 \n"
+		:[result]"+r"(result)
+		:[var1]"r"(var1), [var2]"r"(var2)
+		:"r2", "r3"
+		); 
+	return result;
+#else
+    Word16 var_out;
+    Word32 L_product;
+
+    L_product = (Word32) var1 *(Word32) var2;
+    L_product = (L_product & (Word32) 0xffff8000L) >> 15;
+    if (L_product & (Word32) 0x00010000L)
+        L_product = L_product | (Word32) 0xffff0000L;
+    var_out = saturate(L_product);
+
+    return (var_out);
+#endif
+}
+#endif
+
+
+/* Short norm,           15  */
+#if (NORM_S_IS_INLINE)
+__inline Word16 norm_s (Word16 var1)
+{
+#if ARMV5TE_NORM_S
+	Word16 result; 
+	asm volatile( 
+		"MOV   r2,%[var1] \n"
+		"CMP   r2, #0\n"
+		"RSBLT %[var1], %[var1], #0 \n"
+		"CLZNE %[result], %[var1]\n"
+		"SUBNE %[result], %[result], #17\n"
+		"MOVEQ %[result], #0\n"
+		"CMP   r2, #-1\n"
+		"MOVEQ %[result], #15\n" 
+		:[result]"+r"(result)
+		:[var1]"r"(var1)
+		:"r2"
+		); 
+	return result;
+#else
+    Word16 var_out;
+
+    if (var1 == 0)
+    {
+        var_out = 0;
+    }
+    else
+    {
+        if (var1 == -1)
+        {
+            var_out = 15;
+        }
+        else
+        {
+            if (var1 < 0)
+            {
+                var1 = (Word16)~var1;
+            }
+            for (var_out = 0; var1 < 0x4000; var_out++)
+            {
+                var1 <<= 1;
+            }
+        }
+    }
+    return (var_out);
+#endif
+}
+#endif
+
+/* Long norm,            30  */
+#if (NORM_L_IS_INLINE)
+__inline Word16 norm_l (Word32 L_var1)
+{
+#if ARMV5TE_NORM_L
+	Word16 result; 
+	asm volatile( 
+		"CMP    %[L_var1], #0\n"
+		"CLZNE  %[result], %[L_var1]\n"
+		"SUBNE  %[result], %[result], #1\n" 
+		"MOVEQ  %[result], #0\n"
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1)
+		); 
+	return result;
+#else
+    //Word16 var_out;
+
+    //if (L_var1 == 0)
+    //{
+    //    var_out = 0;
+    //}
+    //else
+    //{
+    //    if (L_var1 == (Word32) 0xffffffffL)
+    //    {
+    //        var_out = 31;
+    //    }
+    //    else
+    //    {
+    //        if (L_var1 < 0)
+    //        {
+    //            L_var1 = ~L_var1;
+    //        }
+    //        for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
+    //        {
+    //            L_var1 <<= 1;
+    //        }
+    //    }
+    //}
+    //return (var_out);
+  Word16 a16;
+  Word16 r = 0 ;       
+
+   
+  if ( L_var1 < 0 ) {
+    L_var1 = ~L_var1; 
+  }
+
+  if (0 == (L_var1 & 0x7fff8000)) {
+    a16 = extract_l(L_var1);
+    r += 16;
+       
+    if (0 == (a16 & 0x7f80)) {
+      r += 8;
+         
+      if (0 == (a16 & 0x0078)) {
+        r += 4;
+           
+        if (0 == (a16 & 0x0006)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x0001)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x0004)) {
+            r += 1;
+          }
+        }
+      }
+      else {
+           
+        if (0 == (a16 & 0x0060)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x0010)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x0040)) {
+            r += 1;
+          }
+        }
+      }
+    } 
+    else { 
+         
+      if (0 == (a16 & 0x7800)) {
+        r += 4;
+           
+        if (0 == (a16 & 0x0600)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x0100)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x0400)) {
+            r += 1;
+          }
+        }
+      }
+      else {
+           
+        if (0 == (a16 & 0x6000)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x1000)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x4000)) {
+            r += 1;
+          }
+        }
+      }
+    }
+  }
+  else {
+    a16 = extract_h(L_var1);
+       
+    if (0 == (a16 & 0x7f80)) {
+      r += 8;
+         
+      if (0 == (a16 & 0x0078)) {
+        r += 4 ;
+           
+        if (0 == (a16 & 0x0006)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x0001)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x0004)) {
+            r += 1;
+          }
+        }
+      }
+      else {
+           
+        if (0 == (a16 & 0x0060)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x0010)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x0040)) {
+            r += 1;
+          }
+        }
+      }
+    }
+    else {
+         
+      if (0 == (a16 & 0x7800)) {
+        r += 4;
+           
+        if (0 == (a16 & 0x0600)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x0100)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x0400)) {
+            r += 1;
+          }
+        }
+      }
+      else {
+           
+        if (0 == (a16 & 0x6000)) {
+          r += 2;
+             
+          if (0 == (a16 & 0x1000)) {
+            r += 1;
+          }
+        }
+        else {
+             
+          if (0 == (a16 & 0x4000)) {
+            return 1;
+          }
+        }
+      }
+    }
+  }
+  
+  return r ;
+#endif
+}
+#endif
+
+/* Round,               1   */
+#if (ROUND_IS_INLINE)
+__inline Word16 round16(Word32 L_var1)
+{
+#if ARMV5TE_ROUND
+	Word16 result; 
+	asm volatile( 
+		"MOV   r1,#0x00008000\n"
+		"QADD  %[result], %[L_var1], r1\n"
+		"MOV   %[result], %[result], ASR #16 \n" 
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1)
+		:"r1"
+		); 
+	return result;
+#else   
+    Word16 var_out;
+    Word32 L_rounded;
+
+    L_rounded = L_add (L_var1, (Word32) 0x00008000L);
+    var_out = extract_h (L_rounded);
+    return (var_out);
+#endif
+}
+#endif
+
+/* Mac,  1  */
+#if (L_MAC_IS_INLINE)
+__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
+{
+#if ARMV5TE_L_MAC
+	Word32 result; 
+	asm volatile( 
+		"SMULBB %[result], %[var1], %[var2]\n"
+		"QADD	%[result], %[result], %[result]\n"
+		"QADD   %[result], %[result], %[L_var3]\n"
+		:[result]"+r"(result)
+		: [L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)
+		); 
+	return result;
+#else
+    Word32 L_var_out;
+    Word32 L_product;
+
+    L_product = L_mult(var1, var2);
+    L_var_out = L_add (L_var3, L_product);
+    return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_ADD_IS_INLINE)
+__inline Word32 L_add (Word32 L_var1, Word32 L_var2)
+{
+#if ARMV5TE_L_ADD
+	Word32 result; 
+	asm volatile( 
+		"QADD %[result], %[L_var1], %[L_var2]\n"
+		:[result]"+r"(result)
+		:[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)
+		); 
+	return result;
+#else
+    Word32 L_var_out;
+
+    L_var_out = L_var1 + L_var2;
+    if (((L_var1 ^ L_var2) & MIN_32) == 0)
+    {
+        if ((L_var_out ^ L_var1) & MIN_32)
+        {
+            L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
+        }
+    }
+    return (L_var_out);
+#endif
+}
+#endif
+
+
+
+#if (MULT_R_IS_INLINE)
+__inline Word16 mult_r (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+    Word32 L_product_arr;
+
+    L_product_arr = (Word32)var1 *(Word32)var2;       /* product */
+    L_product_arr += (Word32)0x00004000L;      /* round */
+    L_product_arr >>= 15;       /* shift */
+
+    var_out = saturate(L_product_arr);
+
+    return (var_out);
+}
+#endif
+
+#if (SHR_R_IS_INLINE)
+__inline Word16 shr_r (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    if (var2 > 15)
+    {
+        var_out = 0;
+    }
+    else
+    {
+        var_out = shr(var1, var2);
+
+        if (var2 > 0)
+        {
+            if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
+            {
+                var_out++;
+            }
+        }
+    }
+
+    return (var_out);
+}
+#endif
+
+#if (MAC_R_IS_INLINE)
+__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    L_var3 = L_mac (L_var3, var1, var2);
+    var_out = (Word16)((L_var3 + 0x8000L) >> 16);
+
+    return (var_out);
+}
+#endif
+
+#if (MSU_R_IS_INLINE)
+__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    L_var3 = L_msu (L_var3, var1, var2);
+    var_out = (Word16)((L_var3 + 0x8000L) >> 16);
+    
+    return (var_out);
+}
+#endif
+
+#if (L_SHR_R_IS_INLINE)
+__inline Word32 L_shr_r (Word32 L_var1, Word16 var2)
+{
+    Word32 L_var_out;
+
+    if (var2 > 31)
+    {
+        L_var_out = 0;
+    }
+    else
+    {
+        L_var_out = L_shr(L_var1, var2);
+
+        if (var2 > 0)
+        {
+            if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+            {
+                L_var_out++;
+            }
+        }
+    }
+
+    return (L_var_out);
+}
+#endif
+
+#if (EXTRACT_H_IS_INLINE)
+__inline Word16 extract_h (Word32 L_var1)
+{
+    Word16 var_out;
+
+    var_out = (Word16) (L_var1 >> 16);
+
+    return (var_out);
+}
+#endif
+
+#if (EXTRACT_L_IS_INLINE)
+__inline Word16 extract_l(Word32 L_var1)
+{
+	return (Word16) L_var1;
+}
+#endif
+
 #endif
diff --git a/media/libstagefright/codecs/aacenc/basic_op/basicop2.c b/media/libstagefright/codecs/aacenc/basic_op/basicop2.c
index a0d5dba..82d3f38 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/basicop2.c
+++ b/media/libstagefright/codecs/aacenc/basic_op/basicop2.c
@@ -1,1624 +1,1624 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		basicop2.c

-

-	Content:	Basic arithmetic operators. 

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		basicop2.c
+
+	Content:	Basic arithmetic operators. 
+
 *******************************************************************************/
 
 #include "typedef.h"
-#include "basic_op.h"

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Functions                                                               |

- |___________________________________________________________________________|

-*/

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : saturate                                                |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |    Limit the 32 bit input to the range of a 16 bit word.                  |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-

-#if (!SATRUATE_IS_INLINE)

-Word16 saturate(Word32 L_var1)

-{

-    Word16 var_out;

-

-    if (L_var1 > 0X00007fffL)

-    {

-        var_out = MAX_16;

-    }

-    else if (L_var1 < (Word32) 0xffff8000L)

-    {

-        var_out = MIN_16;

-    }

-    else

-    {

-        var_out = extract_l(L_var1);

-    }

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : add                                                     |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |    Performs the addition (var1+var2) with overflow control and saturation;|

- |    the 16 bit result is set at +32767 when overflow occurs or at -32768   |

- |    when underflow occurs.                                                 |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-

-#if (!ADD_IS_INLINE)

-Word16 add (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-    Word32 L_sum;

-

-    L_sum = (Word32)var1 + (Word32)var2;

-    var_out = saturate(L_sum);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : sub                                                     |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |    Performs the subtraction (var1+var2) with overflow control and satu-   |

- |    ration; the 16 bit result is set at +32767 when overflow occurs or at  |

- |    -32768 when underflow occurs.                                          |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-#if (!SUB_IS_INLINE)

-Word16 sub(Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-    Word32 L_diff;

-

-    L_diff = (Word32) var1 - var2;

-    var_out = saturate(L_diff);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : abs_s                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |    Absolute value of var1; abs_s(-32768) = 32767.                         |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-//Word16 abs_s (Word16 var1)

-//{

-//    Word16 var_out;

-//

-//    if (var1 == MIN_16)

-//    {

-//        var_out = MAX_16;

-//    }

-//    else

-//    {

-//        if (var1 < 0)

-//        {

-//            var_out = (Word16)-var1;

-//        }

-//        else

-//        {

-//            var_out = var1;

-//        }

-//    }

-//

-//    return (var_out);

-//}

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : shl                                                     |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|

- |   the var2 LSB of the result. If var2 is negative, arithmetically shift   |

- |   var1 right by -var2 with sign extension. Saturate the result in case of |

- |   underflows or overflows.                                                |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-

-#if (!SHL_IS_INLINE)

-Word16 shl (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-    Word32 result;

-

-    if (var2 < 0)

-    {

-        if (var2 < -16)

-            var2 = -16;

-        var_out = shr (var1, (Word16)-var2);

-    }

-    else

-    {

-        result = (Word32) var1 *((Word32) 1 << var2);

-

-        if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))

-        {

-            //Overflow = 1;

-            var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);

-        }

-        else

-        {

-            var_out = extract_l(result);

-        }

-    }

-

-    return (var_out);

-}

-#endif

-// end

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : shr                                                     |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Arithmetically shift the 16 bit input var1 right var2 positions with    |

- |   sign extension. If var2 is negative, arithmetically shift var1 left by  |

- |   -var2 with sign extension. Saturate the result in case of underflows or |

- |   overflows.                                                              |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-

-#if (!SHR_IS_INLINE)

-Word16 shr (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    if (var2 < 0)

-    {

-        if (var2 < -16)

-            var2 = -16;

-        var_out = shl (var1, (Word16)-var2);

-    }

-    else

-    {

-        if (var2 >= 15)

-        {

-            var_out = (Word16)((var1 < 0) ? -1 : 0);

-        }

-        else

-        {

-            if (var1 < 0)

-            {

-                var_out = (Word16)(~((~var1) >> var2));

-            }

-            else

-            {

-                var_out = (Word16)(var1 >> var2);

-            }

-        }

-    }

-

-    return (var_out);

-}

-#endif

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : mult                                                    |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |    Performs the multiplication of var1 by var2 and gives a 16 bit result  |

- |    which is scaled i.e.:                                                  |

- |             mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and  |

- |             mult(-32768,-32768) = 32767.                                  |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-#if (!MULT_IS_INLINE)

-Word16 mult (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-    Word32 L_product;

-

-    L_product = (Word32) var1 *(Word32) var2;

-

-    L_product = (L_product & (Word32) 0xffff8000L) >> 15;

-

-    if (L_product & (Word32) 0x00010000L)

-        L_product = L_product | (Word32) 0xffff0000L;

-

-    var_out = saturate(L_product);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_mult                                                  |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   L_mult is the 32 bit result of the multiplication of var1 times var2    |

- |   with one shift left i.e.:                                               |

- |        L_mult(var1,var2) = L_shl((var1 times var2),1) and                 |

- |        L_mult(-32768,-32768) = 2147483647.                                |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-

-#if (!L_MULT_IS_INLINE)

-Word32 L_mult(Word16 var1, Word16 var2)

-{

-    Word32 L_var_out;

-

-    L_var_out = (Word32) var1 *(Word32) var2;

-

-    if (L_var_out != (Word32) 0x40000000L)

-    {

-        L_var_out <<= 1;

-    }

-    else

-    {

-        L_var_out = MAX_32;

-    }

-        

-    return (L_var_out);

-}

-#endif

-// end

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : negate                                                  |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Negate var1 with saturation, saturate in the case where input is -32768:|

- |                negate(var1) = sub(0,var1).                                |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-//Word16 negate (Word16 var1)

-//{

-//    Word16 var_out;

-//

-//    var_out = (Word16)((var1 == MIN_16) ? MAX_16 : -var1);

-//

-//    return (var_out);

-//}

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : extract_h                                               |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Return the 16 MSB of L_var1.                                            |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32 ) whose value falls in the |

- |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-#if (!EXTRACT_H_IS_INLINE)

-Word16 extract_h (Word32 L_var1)

-{

-    Word16 var_out;

-

-    var_out = (Word16) (L_var1 >> 16);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : extract_l                                               |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Return the 16 LSB of L_var1.                                            |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32 ) whose value falls in the |

- |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-#if (!EXTRACT_L_IS_INLINE)

-Word16 extract_l(Word32 L_var1)

-{

-    Word16 var_out;

-

-    var_out = (Word16) L_var1;

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : round                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Round the lower 16 bits of the 32 bit input number into the MS 16 bits  |

- |   with saturation. Shift the resulting bits right by 16 and return the 16 |

- |   bit number:                                                             |

- |               round(L_var1) = extract_h(L_add(L_var1,32768))              |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32 ) whose value falls in the |

- |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-

-#if (!ROUND_IS_INLINE)

-Word16 round16(Word32 L_var1)

-{

-    Word16 var_out;

-    Word32 L_rounded;

-

-    L_rounded = L_add (L_var1, (Word32) 0x00008000L);

-    var_out = extract_h (L_rounded);

-

-    return (var_out);

-}

-#endif

-// end

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_mac                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |

- |   result to L_var3 with saturation, return a 32 bit result:               |

- |        L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)).         |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-#if (!L_MSU_IS_INLINE)

-Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)

-{

-    Word32 L_var_out;

-    Word32 L_product;

-

-    L_product = L_mult(var1, var2);

-    L_var_out = L_add (L_var3, L_product);

-

-    return (L_var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_msu                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |

- |   bit result to L_var3 with saturation, return a 32 bit result:           |

- |        L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).         |

- |                                                                           |

- |   Complexity weight : 1                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-

-#if (!L_MSU_IS_INLINE)

-Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)

-{

-    Word32 L_var_out;

-    Word32 L_product;

-

-    L_product = L_mult(var1, var2);

-    L_var_out = L_sub (L_var3, L_product);

-

-    return (L_var_out);

-}

-#endif

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_add                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   32 bits addition of the two 32 bits variables (L_var1+L_var2) with      |

- |   overflow control and saturation; the result is set at +2147483647 when  |

- |   overflow occurs or at -2147483648 when underflow occurs.                |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-#if (!L_ADD_IS_INLINE)

-Word32 L_add (Word32 L_var1, Word32 L_var2)

-{

-    Word32 L_var_out;

-

-    L_var_out = L_var1 + L_var2;

-

-    if (((L_var1 ^ L_var2) & MIN_32) == 0)

-    {

-        if ((L_var_out ^ L_var1) & MIN_32)

-        {

-            L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;

-            //Overflow = 1;

-        }

-    }

-

-    return (L_var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_sub                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with   |

- |   overflow control and saturation; the result is set at +2147483647 when  |

- |   overflow occurs or at -2147483648 when underflow occurs.                |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-#if (!L_SUB_IS_INLINE)

-Word32 L_sub(Word32 L_var1, Word32 L_var2)

-{

-    Word32 L_var_out;

-

-    L_var_out = L_var1 - L_var2;

-

-    if (((L_var1 ^ L_var2) & MIN_32) != 0)

-    {

-        if ((L_var_out ^ L_var1) & MIN_32)

-        {

-            L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;

-            //Overflow = 1;

-        }

-    }

-

-    return (L_var_out);

-}

-#endif

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_negate                                                |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Negate the 32 bit variable L_var1 with saturation; saturate in the case |

- |   where input is -2147483648 (0x8000 0000).                               |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-//Word32 L_negate (Word32 L_var1)

-//{

-//    Word32 L_var_out;

-//

-//    L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1;

-//

-//    return (L_var_out);

-//}

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : mult_r                                                  |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Same as mult with rounding, i.e.:                                       |

- |     mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and  |

- |     mult_r(-32768,-32768) = 32767.                                        |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-#if (!MULT_R_IS_INLINE)

-Word16 mult_r (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-    Word32 L_product_arr;

-

-    L_product_arr = (Word32) var1 *(Word32) var2;       /* product */

-    L_product_arr += (Word32) 0x00004000L;      /* round */

-    L_product_arr &= (Word32) 0xffff8000L;

-    L_product_arr >>= 15;       /* shift */

-

-    if (L_product_arr & (Word32) 0x00010000L)   /* sign extend when necessary */

-    {

-        L_product_arr |= (Word32) 0xffff0000L;

-    }

-    var_out = saturate(L_product_arr);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_shl                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero  |

- |   fill the var2 LSB of the result. If var2 is negative, arithmetically    |

- |   shift L_var1 right by -var2 with sign extension. Saturate the result in |

- |   case of underflows or overflows.                                        |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-

-#if (!L_SHL_IS_INLINE)

-Word32 L_shl (Word32 L_var1, Word16 var2)

-{

-    Word32 L_var_out = 0L;

-

-    if (var2 <= 0)

-    {

-        L_var1 = L_shr(L_var1, (Word16)-var2);

-    }

-    else

-    {

-        for (; var2 > 0; var2--)

-        {

-            if (L_var1 > (Word32) 0X3fffffffL)

-            {

-                return MAX_32;

-            }

-            else

-            {

-                if (L_var1 < (Word32) 0xc0000000L)

-                {

-                    return MIN_32;

-                }

-            }

-            L_var1 <<= 1;

-        }

-    }

-    return (L_var1);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_shr                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Arithmetically shift the 32 bit input L_var1 right var2 positions with  |

- |   sign extension. If var2 is negative, arithmetically shift L_var1 left   |

- |   by -var2 and zero fill the -var2 LSB of the result. Saturate the result |

- |   in case of underflows or overflows.                                     |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |

- |___________________________________________________________________________|

-*/

-

-#if (!L_SHR_IS_INLINE)

-Word32 L_shr (Word32 L_var1, Word16 var2)

-{

-    Word32 L_var_out;

-

-    if (var2 < 0)

-    {

-        L_var_out = L_shl (L_var1, (Word16)-var2);

-    }

-    else

-    {

-        if (var2 >= 31)

-        {

-            L_var_out = (L_var1 < 0L) ? -1 : 0;

-        }

-        else

-        {

-            if (L_var1 < 0)

-            {

-                L_var_out = ~((~L_var1) >> var2);

-            }

-            else

-            {

-                L_var_out = L_var1 >> var2;

-            }

-        }

-    }

-    return (L_var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : shr_r                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Same as shr(var1,var2) but with rounding. Saturate the result in case of|

- |   underflows or overflows :                                               |

- |    - If var2 is greater than zero :                                       |

- |          if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1))))            |

- |          is equal to zero                                                 |

- |                     then                                                  |

- |                     shr_r(var1,var2) = shr(var1,var2)                     |

- |                     else                                                  |

- |                     shr_r(var1,var2) = add(shr(var1,var2),1)              |

- |    - If var2 is less than or equal to zero :                              |

- |                     shr_r(var1,var2) = shr(var1,var2).                    |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-#if (!SHR_R_IS_INLINE)

-Word16 shr_r (Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    if (var2 > 15)

-    {

-        var_out = 0;

-    }

-    else

-    {

-        var_out = shr (var1, var2);

-

-        if (var2 > 0)

-        {

-            if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)

-            {

-                var_out++;

-            }

-        }

-    }

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : mac_r                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |

- |   result to L_var3 with saturation. Round the LS 16 bits of the result    |

- |   into the MS 16 bits with saturation and shift the result right by 16.   |

- |   Return a 16 bit result.                                                 |

- |            mac_r(L_var3,var1,var2) = round(L_mac(L_var3,var1,var2))       |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |

- |___________________________________________________________________________|

-*/

-#if (!MAC_R_IS_INLINE)

-Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    L_var3 = L_mac (L_var3, var1, var2);

-    L_var3 = L_add (L_var3, (Word32) 0x00008000L);

-    var_out = extract_h (L_var3);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : msu_r                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |

- |   bit result to L_var3 with saturation. Round the LS 16 bits of the res-  |

- |   ult into the MS 16 bits with saturation and shift the result right by   |

- |   16. Return a 16 bit result.                                             |

- |            msu_r(L_var3,var1,var2) = round(L_msu(L_var3,var1,var2))       |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |

- |___________________________________________________________________________|

-*/

-#if (!MSU_R_IS_INLINE)

-Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)

-{

-    Word16 var_out;

-

-    L_var3 = L_msu (L_var3, var1, var2);

-    L_var3 = L_add (L_var3, (Word32) 0x00008000L);

-    var_out = extract_h (L_var3);

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_deposit_h                                             |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The   |

- |   16 LS bits of the output are zeroed.                                    |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= var_out <= 0x7fff 0000.                |

- |___________________________________________________________________________|

-*/

-//Word32 L_deposit_h (Word16 var1)

-//{

-//    Word32 L_var_out;

-//

-//    L_var_out = (Word32) var1 << 16;

-//

-//    return (L_var_out);

-//}

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_deposit_l                                             |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The   |

- |   16 MS bits of the output are sign extended.                             |

- |                                                                           |

- |   Complexity weight : 2                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0xFFFF 8000 <= var_out <= 0x0000 7fff.                |

- |___________________________________________________________________________|

-*/

-//Word32 L_deposit_l (Word16 var1)

-//{

-//    Word32 L_var_out;

-//

-//    L_var_out = (Word32) var1;

-//

-//    return (L_var_out);

-//}

-

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_shr_r                                                 |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Same as L_shr(L_var1,var2) but with rounding. Saturate the result in    |

- |   case of underflows or overflows :                                       |

- |    - If var2 is greater than zero :                                       |

- |          if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|

- |          is equal to zero                                                 |

- |                     then                                                  |

- |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2)             |

- |                     else                                                  |

- |                     L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1)    |

- |    - If var2 is less than or equal to zero :                              |

- |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2).            |

- |                                                                           |

- |   Complexity weight : 3                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |

- |___________________________________________________________________________|

-*/

-#if (!L_SHR_R_IS_INLINE)

-Word32 L_shr_r (Word32 L_var1, Word16 var2)

-{

-    Word32 L_var_out;

-

-    if (var2 > 31)

-    {

-        L_var_out = 0;

-    }

-    else

-    {

-        L_var_out = L_shr (L_var1, var2);

-

-        if (var2 > 0)

-        {

-            if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)

-            {

-                L_var_out++;

-            }

-        }

-    }

-

-    return (L_var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : L_abs                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |    Absolute value of L_var1; Saturate in case where the input is          |

- |                                                               -214783648  |

- |                                                                           |

- |   Complexity weight : 3                                                   |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    L_var_out                                                              |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x0000 0000 <= var_out <= 0x7fff ffff.                |

- |___________________________________________________________________________|

-*/

-//Word32 L_abs (Word32 L_var1)

-//{

-//    Word32 L_var_out;

-//

-//    if (L_var1 == MIN_32)

-//    {

-//        L_var_out = MAX_32;

-//    }

-//    else

-//    {

-//        if (L_var1 < 0)

-//        {

-//            L_var_out = -L_var1;

-//        }

-//        else

-//        {

-//            L_var_out = L_var1;

-//        }

-//    }

-//

-//    return (L_var_out);

-//}

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : norm_s                                                  |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Produces the number of left shift needed to normalize the 16 bit varia- |

- |   ble var1 for positive values on the interval with minimum of 16384 and  |

- |   maximum of 32767, and for negative values on the interval with minimum  |

- |   of -32768 and maximum of -16384; in order to normalize the result, the  |

- |   following operation must be done :                                      |

- |                    norm_var1 = shl(var1,norm_s(var1)).                    |

- |                                                                           |

- |   Complexity weight : 15                                                  |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 0000 <= var_out <= 0x0000 000f.                |

- |___________________________________________________________________________|

-*/

-

-#if (!NORM_S_IS_INLINE)

-Word16 norm_s (Word16 var1)

-{

-    Word16 var_out;

-

-    if (var1 == 0)

-    {

-        var_out = 0;

-    }

-    else

-    {

-        if (var1 == -1)

-        {

-            var_out = 15;

-        }

-        else

-        {

-            if (var1 < 0)

-            {

-                var1 = (Word16)~var1;

-            }

-            for (var_out = 0; var1 < 0x4000; var_out++)

-            {

-                var1 <<= 1;

-            }

-        }

-    }

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : div_s                                                   |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Produces a result which is the fractional integer division of var1  by  |

- |   var2; var1 and var2 must be positive and var2 must be greater or equal  |

- |   to var1; the result is positive (leading bit equal to 0) and truncated  |

- |   to 16 bits.                                                             |

- |   If var1 = var2 then div(var1,var2) = 32767.                             |

- |                                                                           |

- |   Complexity weight : 18                                                  |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    var1                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 0000 <= var1 <= var2 and var2 != 0.            |

- |                                                                           |

- |    var2                                                                   |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : var1 <= var2 <= 0x0000 7fff and var2 != 0.            |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |

- |             It's a Q15 value (point between b15 and b14).                 |

- |___________________________________________________________________________|

-*/

-

-#if (!DIV_S_IS_INLINE)

-Word16 div_s (Word16 var1, Word16 var2)

-{

-    Word16 var_out = 0;

-    Word16 iteration;

-    Word32 L_num;

-    Word32 L_denom;

-

-    if (var1 == 0)

-    {

-        var_out = 0;

-    }

-    else

-    {

-        if (var1 == var2)

-        {

-            var_out = MAX_16;

-        }

-        else

-        {

-            L_num = L_deposit_l (var1);

-            L_denom = L_deposit_l (var2);

-

-            for (iteration = 0; iteration < 15; iteration++)

-            {

-                var_out <<= 1;

-                L_num <<= 1;

-

-                if (L_num >= L_denom)

-                {

-                    L_num = L_sub(L_num, L_denom);

-                    var_out = add (var_out, 1);

-                }

-            }

-        }

-    }

-

-    return (var_out);

-}

-#endif

-

-/*___________________________________________________________________________

- |                                                                           |

- |   Function Name : norm_l                                                  |

- |                                                                           |

- |   Purpose :                                                               |

- |                                                                           |

- |   Produces the number of left shifts needed to normalize the 32 bit varia-|

- |   ble L_var1 for positive values on the interval with minimum of          |

- |   1073741824 and maximum of 2147483647, and for negative values on the in-|

- |   terval with minimum of -2147483648 and maximum of -1073741824; in order |

- |   to normalize the result, the following operation must be done :         |

- |                   norm_L_var1 = L_shl(L_var1,norm_l(L_var1)).             |

- |                                                                           |

- |   Complexity weight : 30                                                  |

- |                                                                           |

- |   Inputs :                                                                |

- |                                                                           |

- |    L_var1                                                                 |

- |             32 bit long signed integer (Word32) whose value falls in the  |

- |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |

- |                                                                           |

- |   Outputs :                                                               |

- |                                                                           |

- |    none                                                                   |

- |                                                                           |

- |   Return Value :                                                          |

- |                                                                           |

- |    var_out                                                                |

- |             16 bit short signed integer (Word16) whose value falls in the |

- |             range : 0x0000 0000 <= var_out <= 0x0000 001f.                |

- |___________________________________________________________________________|

-*/

-

-#if (!NORM_L_IS_INLINE)

-Word16 norm_l (Word32 L_var1)

-{

-    Word16 var_out;

-

-    if (L_var1 == 0)

-    {

-        var_out = 0;

-    }

-    else

-    {

-        if (L_var1 == (Word32) 0xffffffffL)

-        {

-            var_out = 31;

-        }

-        else

-        {

-            if (L_var1 < 0)

-            {

-                L_var1 = ~L_var1;

-            }

-            for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)

-            {

-                L_var1 <<= 1;

-            }

-        }

-    }

-

-    return (var_out);

-}

-#endif

+#include "basic_op.h"
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Functions                                                               |
+ |___________________________________________________________________________|
+*/
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : saturate                                                |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |    Limit the 32 bit input to the range of a 16 bit word.                  |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!SATRUATE_IS_INLINE)
+Word16 saturate(Word32 L_var1)
+{
+    Word16 var_out;
+
+    if (L_var1 > 0X00007fffL)
+    {
+        var_out = MAX_16;
+    }
+    else if (L_var1 < (Word32) 0xffff8000L)
+    {
+        var_out = MIN_16;
+    }
+    else
+    {
+        var_out = extract_l(L_var1);
+    }
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : add                                                     |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |    Performs the addition (var1+var2) with overflow control and saturation;|
+ |    the 16 bit result is set at +32767 when overflow occurs or at -32768   |
+ |    when underflow occurs.                                                 |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!ADD_IS_INLINE)
+Word16 add (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+    Word32 L_sum;
+
+    L_sum = (Word32)var1 + (Word32)var2;
+    var_out = saturate(L_sum);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : sub                                                     |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |    Performs the subtraction (var1+var2) with overflow control and satu-   |
+ |    ration; the 16 bit result is set at +32767 when overflow occurs or at  |
+ |    -32768 when underflow occurs.                                          |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+#if (!SUB_IS_INLINE)
+Word16 sub(Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+    Word32 L_diff;
+
+    L_diff = (Word32) var1 - var2;
+    var_out = saturate(L_diff);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : abs_s                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |    Absolute value of var1; abs_s(-32768) = 32767.                         |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+//Word16 abs_s (Word16 var1)
+//{
+//    Word16 var_out;
+//
+//    if (var1 == MIN_16)
+//    {
+//        var_out = MAX_16;
+//    }
+//    else
+//    {
+//        if (var1 < 0)
+//        {
+//            var_out = (Word16)-var1;
+//        }
+//        else
+//        {
+//            var_out = var1;
+//        }
+//    }
+//
+//    return (var_out);
+//}
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : shl                                                     |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
+ |   the var2 LSB of the result. If var2 is negative, arithmetically shift   |
+ |   var1 right by -var2 with sign extension. Saturate the result in case of |
+ |   underflows or overflows.                                                |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!SHL_IS_INLINE)
+Word16 shl (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+    Word32 result;
+
+    if (var2 < 0)
+    {
+        if (var2 < -16)
+            var2 = -16;
+        var_out = shr (var1, (Word16)-var2);
+    }
+    else
+    {
+        result = (Word32) var1 *((Word32) 1 << var2);
+
+        if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
+        {
+            //Overflow = 1;
+            var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
+        }
+        else
+        {
+            var_out = extract_l(result);
+        }
+    }
+
+    return (var_out);
+}
+#endif
+// end
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : shr                                                     |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Arithmetically shift the 16 bit input var1 right var2 positions with    |
+ |   sign extension. If var2 is negative, arithmetically shift var1 left by  |
+ |   -var2 with sign extension. Saturate the result in case of underflows or |
+ |   overflows.                                                              |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!SHR_IS_INLINE)
+Word16 shr (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    if (var2 < 0)
+    {
+        if (var2 < -16)
+            var2 = -16;
+        var_out = shl (var1, (Word16)-var2);
+    }
+    else
+    {
+        if (var2 >= 15)
+        {
+            var_out = (Word16)((var1 < 0) ? -1 : 0);
+        }
+        else
+        {
+            if (var1 < 0)
+            {
+                var_out = (Word16)(~((~var1) >> var2));
+            }
+            else
+            {
+                var_out = (Word16)(var1 >> var2);
+            }
+        }
+    }
+
+    return (var_out);
+}
+#endif
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : mult                                                    |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |    Performs the multiplication of var1 by var2 and gives a 16 bit result  |
+ |    which is scaled i.e.:                                                  |
+ |             mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and  |
+ |             mult(-32768,-32768) = 32767.                                  |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+#if (!MULT_IS_INLINE)
+Word16 mult (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+    Word32 L_product;
+
+    L_product = (Word32) var1 *(Word32) var2;
+
+    L_product = (L_product & (Word32) 0xffff8000L) >> 15;
+
+    if (L_product & (Word32) 0x00010000L)
+        L_product = L_product | (Word32) 0xffff0000L;
+
+    var_out = saturate(L_product);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_mult                                                  |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   L_mult is the 32 bit result of the multiplication of var1 times var2    |
+ |   with one shift left i.e.:                                               |
+ |        L_mult(var1,var2) = L_shl((var1 times var2),1) and                 |
+ |        L_mult(-32768,-32768) = 2147483647.                                |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_MULT_IS_INLINE)
+Word32 L_mult(Word16 var1, Word16 var2)
+{
+    Word32 L_var_out;
+
+    L_var_out = (Word32) var1 *(Word32) var2;
+
+    if (L_var_out != (Word32) 0x40000000L)
+    {
+        L_var_out <<= 1;
+    }
+    else
+    {
+        L_var_out = MAX_32;
+    }
+        
+    return (L_var_out);
+}
+#endif
+// end
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : negate                                                  |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Negate var1 with saturation, saturate in the case where input is -32768:|
+ |                negate(var1) = sub(0,var1).                                |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+//Word16 negate (Word16 var1)
+//{
+//    Word16 var_out;
+//
+//    var_out = (Word16)((var1 == MIN_16) ? MAX_16 : -var1);
+//
+//    return (var_out);
+//}
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : extract_h                                               |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Return the 16 MSB of L_var1.                                            |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32 ) whose value falls in the |
+ |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+#if (!EXTRACT_H_IS_INLINE)
+Word16 extract_h (Word32 L_var1)
+{
+    Word16 var_out;
+
+    var_out = (Word16) (L_var1 >> 16);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : extract_l                                               |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Return the 16 LSB of L_var1.                                            |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32 ) whose value falls in the |
+ |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+#if (!EXTRACT_L_IS_INLINE)
+Word16 extract_l(Word32 L_var1)
+{
+    Word16 var_out;
+
+    var_out = (Word16) L_var1;
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : round                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Round the lower 16 bits of the 32 bit input number into the MS 16 bits  |
+ |   with saturation. Shift the resulting bits right by 16 and return the 16 |
+ |   bit number:                                                             |
+ |               round(L_var1) = extract_h(L_add(L_var1,32768))              |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32 ) whose value falls in the |
+ |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!ROUND_IS_INLINE)
+Word16 round16(Word32 L_var1)
+{
+    Word16 var_out;
+    Word32 L_rounded;
+
+    L_rounded = L_add (L_var1, (Word32) 0x00008000L);
+    var_out = extract_h (L_rounded);
+
+    return (var_out);
+}
+#endif
+// end
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_mac                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
+ |   result to L_var3 with saturation, return a 32 bit result:               |
+ |        L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)).         |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+#if (!L_MSU_IS_INLINE)
+Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
+{
+    Word32 L_var_out;
+    Word32 L_product;
+
+    L_product = L_mult(var1, var2);
+    L_var_out = L_add (L_var3, L_product);
+
+    return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_msu                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
+ |   bit result to L_var3 with saturation, return a 32 bit result:           |
+ |        L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).         |
+ |                                                                           |
+ |   Complexity weight : 1                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_MSU_IS_INLINE)
+Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
+{
+    Word32 L_var_out;
+    Word32 L_product;
+
+    L_product = L_mult(var1, var2);
+    L_var_out = L_sub (L_var3, L_product);
+
+    return (L_var_out);
+}
+#endif
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_add                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   32 bits addition of the two 32 bits variables (L_var1+L_var2) with      |
+ |   overflow control and saturation; the result is set at +2147483647 when  |
+ |   overflow occurs or at -2147483648 when underflow occurs.                |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+#if (!L_ADD_IS_INLINE)
+Word32 L_add (Word32 L_var1, Word32 L_var2)
+{
+    Word32 L_var_out;
+
+    L_var_out = L_var1 + L_var2;
+
+    if (((L_var1 ^ L_var2) & MIN_32) == 0)
+    {
+        if ((L_var_out ^ L_var1) & MIN_32)
+        {
+            L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
+            //Overflow = 1;
+        }
+    }
+
+    return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_sub                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with   |
+ |   overflow control and saturation; the result is set at +2147483647 when  |
+ |   overflow occurs or at -2147483648 when underflow occurs.                |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+#if (!L_SUB_IS_INLINE)
+Word32 L_sub(Word32 L_var1, Word32 L_var2)
+{
+    Word32 L_var_out;
+
+    L_var_out = L_var1 - L_var2;
+
+    if (((L_var1 ^ L_var2) & MIN_32) != 0)
+    {
+        if ((L_var_out ^ L_var1) & MIN_32)
+        {
+            L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
+            //Overflow = 1;
+        }
+    }
+
+    return (L_var_out);
+}
+#endif
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_negate                                                |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Negate the 32 bit variable L_var1 with saturation; saturate in the case |
+ |   where input is -2147483648 (0x8000 0000).                               |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+//Word32 L_negate (Word32 L_var1)
+//{
+//    Word32 L_var_out;
+//
+//    L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1;
+//
+//    return (L_var_out);
+//}
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : mult_r                                                  |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Same as mult with rounding, i.e.:                                       |
+ |     mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and  |
+ |     mult_r(-32768,-32768) = 32767.                                        |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+#if (!MULT_R_IS_INLINE)
+Word16 mult_r (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+    Word32 L_product_arr;
+
+    L_product_arr = (Word32) var1 *(Word32) var2;       /* product */
+    L_product_arr += (Word32) 0x00004000L;      /* round */
+    L_product_arr &= (Word32) 0xffff8000L;
+    L_product_arr >>= 15;       /* shift */
+
+    if (L_product_arr & (Word32) 0x00010000L)   /* sign extend when necessary */
+    {
+        L_product_arr |= (Word32) 0xffff0000L;
+    }
+    var_out = saturate(L_product_arr);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_shl                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero  |
+ |   fill the var2 LSB of the result. If var2 is negative, arithmetically    |
+ |   shift L_var1 right by -var2 with sign extension. Saturate the result in |
+ |   case of underflows or overflows.                                        |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_SHL_IS_INLINE)
+Word32 L_shl (Word32 L_var1, Word16 var2)
+{
+    Word32 L_var_out = 0L;
+
+    if (var2 <= 0)
+    {
+        L_var1 = L_shr(L_var1, (Word16)-var2);
+    }
+    else
+    {
+        for (; var2 > 0; var2--)
+        {
+            if (L_var1 > (Word32) 0X3fffffffL)
+            {
+                return MAX_32;
+            }
+            else
+            {
+                if (L_var1 < (Word32) 0xc0000000L)
+                {
+                    return MIN_32;
+                }
+            }
+            L_var1 <<= 1;
+        }
+    }
+    return (L_var1);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_shr                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Arithmetically shift the 32 bit input L_var1 right var2 positions with  |
+ |   sign extension. If var2 is negative, arithmetically shift L_var1 left   |
+ |   by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
+ |   in case of underflows or overflows.                                     |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_SHR_IS_INLINE)
+Word32 L_shr (Word32 L_var1, Word16 var2)
+{
+    Word32 L_var_out;
+
+    if (var2 < 0)
+    {
+        L_var_out = L_shl (L_var1, (Word16)-var2);
+    }
+    else
+    {
+        if (var2 >= 31)
+        {
+            L_var_out = (L_var1 < 0L) ? -1 : 0;
+        }
+        else
+        {
+            if (L_var1 < 0)
+            {
+                L_var_out = ~((~L_var1) >> var2);
+            }
+            else
+            {
+                L_var_out = L_var1 >> var2;
+            }
+        }
+    }
+    return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : shr_r                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Same as shr(var1,var2) but with rounding. Saturate the result in case of|
+ |   underflows or overflows :                                               |
+ |    - If var2 is greater than zero :                                       |
+ |          if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1))))            |
+ |          is equal to zero                                                 |
+ |                     then                                                  |
+ |                     shr_r(var1,var2) = shr(var1,var2)                     |
+ |                     else                                                  |
+ |                     shr_r(var1,var2) = add(shr(var1,var2),1)              |
+ |    - If var2 is less than or equal to zero :                              |
+ |                     shr_r(var1,var2) = shr(var1,var2).                    |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+#if (!SHR_R_IS_INLINE)
+Word16 shr_r (Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    if (var2 > 15)
+    {
+        var_out = 0;
+    }
+    else
+    {
+        var_out = shr (var1, var2);
+
+        if (var2 > 0)
+        {
+            if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
+            {
+                var_out++;
+            }
+        }
+    }
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : mac_r                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
+ |   result to L_var3 with saturation. Round the LS 16 bits of the result    |
+ |   into the MS 16 bits with saturation and shift the result right by 16.   |
+ |   Return a 16 bit result.                                                 |
+ |            mac_r(L_var3,var1,var2) = round(L_mac(L_var3,var1,var2))       |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |
+ |___________________________________________________________________________|
+*/
+#if (!MAC_R_IS_INLINE)
+Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    L_var3 = L_mac (L_var3, var1, var2);
+    L_var3 = L_add (L_var3, (Word32) 0x00008000L);
+    var_out = extract_h (L_var3);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : msu_r                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
+ |   bit result to L_var3 with saturation. Round the LS 16 bits of the res-  |
+ |   ult into the MS 16 bits with saturation and shift the result right by   |
+ |   16. Return a 16 bit result.                                             |
+ |            msu_r(L_var3,var1,var2) = round(L_msu(L_var3,var1,var2))       |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |
+ |___________________________________________________________________________|
+*/
+#if (!MSU_R_IS_INLINE)
+Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+    Word16 var_out;
+
+    L_var3 = L_msu (L_var3, var1, var2);
+    L_var3 = L_add (L_var3, (Word32) 0x00008000L);
+    var_out = extract_h (L_var3);
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_deposit_h                                             |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The   |
+ |   16 LS bits of the output are zeroed.                                    |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= var_out <= 0x7fff 0000.                |
+ |___________________________________________________________________________|
+*/
+//Word32 L_deposit_h (Word16 var1)
+//{
+//    Word32 L_var_out;
+//
+//    L_var_out = (Word32) var1 << 16;
+//
+//    return (L_var_out);
+//}
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_deposit_l                                             |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The   |
+ |   16 MS bits of the output are sign extended.                             |
+ |                                                                           |
+ |   Complexity weight : 2                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0xFFFF 8000 <= var_out <= 0x0000 7fff.                |
+ |___________________________________________________________________________|
+*/
+//Word32 L_deposit_l (Word16 var1)
+//{
+//    Word32 L_var_out;
+//
+//    L_var_out = (Word32) var1;
+//
+//    return (L_var_out);
+//}
+
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_shr_r                                                 |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Same as L_shr(L_var1,var2) but with rounding. Saturate the result in    |
+ |   case of underflows or overflows :                                       |
+ |    - If var2 is greater than zero :                                       |
+ |          if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
+ |          is equal to zero                                                 |
+ |                     then                                                  |
+ |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2)             |
+ |                     else                                                  |
+ |                     L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1)    |
+ |    - If var2 is less than or equal to zero :                              |
+ |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2).            |
+ |                                                                           |
+ |   Complexity weight : 3                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
+ |___________________________________________________________________________|
+*/
+#if (!L_SHR_R_IS_INLINE)
+Word32 L_shr_r (Word32 L_var1, Word16 var2)
+{
+    Word32 L_var_out;
+
+    if (var2 > 31)
+    {
+        L_var_out = 0;
+    }
+    else
+    {
+        L_var_out = L_shr (L_var1, var2);
+
+        if (var2 > 0)
+        {
+            if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+            {
+                L_var_out++;
+            }
+        }
+    }
+
+    return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : L_abs                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |    Absolute value of L_var1; Saturate in case where the input is          |
+ |                                                               -214783648  |
+ |                                                                           |
+ |   Complexity weight : 3                                                   |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    L_var_out                                                              |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x0000 0000 <= var_out <= 0x7fff ffff.                |
+ |___________________________________________________________________________|
+*/
+//Word32 L_abs (Word32 L_var1)
+//{
+//    Word32 L_var_out;
+//
+//    if (L_var1 == MIN_32)
+//    {
+//        L_var_out = MAX_32;
+//    }
+//    else
+//    {
+//        if (L_var1 < 0)
+//        {
+//            L_var_out = -L_var1;
+//        }
+//        else
+//        {
+//            L_var_out = L_var1;
+//        }
+//    }
+//
+//    return (L_var_out);
+//}
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : norm_s                                                  |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Produces the number of left shift needed to normalize the 16 bit varia- |
+ |   ble var1 for positive values on the interval with minimum of 16384 and  |
+ |   maximum of 32767, and for negative values on the interval with minimum  |
+ |   of -32768 and maximum of -16384; in order to normalize the result, the  |
+ |   following operation must be done :                                      |
+ |                    norm_var1 = shl(var1,norm_s(var1)).                    |
+ |                                                                           |
+ |   Complexity weight : 15                                                  |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 0000 <= var_out <= 0x0000 000f.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!NORM_S_IS_INLINE)
+Word16 norm_s (Word16 var1)
+{
+    Word16 var_out;
+
+    if (var1 == 0)
+    {
+        var_out = 0;
+    }
+    else
+    {
+        if (var1 == -1)
+        {
+            var_out = 15;
+        }
+        else
+        {
+            if (var1 < 0)
+            {
+                var1 = (Word16)~var1;
+            }
+            for (var_out = 0; var1 < 0x4000; var_out++)
+            {
+                var1 <<= 1;
+            }
+        }
+    }
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : div_s                                                   |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Produces a result which is the fractional integer division of var1  by  |
+ |   var2; var1 and var2 must be positive and var2 must be greater or equal  |
+ |   to var1; the result is positive (leading bit equal to 0) and truncated  |
+ |   to 16 bits.                                                             |
+ |   If var1 = var2 then div(var1,var2) = 32767.                             |
+ |                                                                           |
+ |   Complexity weight : 18                                                  |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    var1                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 0000 <= var1 <= var2 and var2 != 0.            |
+ |                                                                           |
+ |    var2                                                                   |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : var1 <= var2 <= 0x0000 7fff and var2 != 0.            |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
+ |             It's a Q15 value (point between b15 and b14).                 |
+ |___________________________________________________________________________|
+*/
+
+#if (!DIV_S_IS_INLINE)
+Word16 div_s (Word16 var1, Word16 var2)
+{
+    Word16 var_out = 0;
+    Word16 iteration;
+    Word32 L_num;
+    Word32 L_denom;
+
+    if (var1 == 0)
+    {
+        var_out = 0;
+    }
+    else
+    {
+        if (var1 == var2)
+        {
+            var_out = MAX_16;
+        }
+        else
+        {
+            L_num = L_deposit_l (var1);
+            L_denom = L_deposit_l (var2);
+
+            for (iteration = 0; iteration < 15; iteration++)
+            {
+                var_out <<= 1;
+                L_num <<= 1;
+
+                if (L_num >= L_denom)
+                {
+                    L_num = L_sub(L_num, L_denom);
+                    var_out = add (var_out, 1);
+                }
+            }
+        }
+    }
+
+    return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ |                                                                           |
+ |   Function Name : norm_l                                                  |
+ |                                                                           |
+ |   Purpose :                                                               |
+ |                                                                           |
+ |   Produces the number of left shifts needed to normalize the 32 bit varia-|
+ |   ble L_var1 for positive values on the interval with minimum of          |
+ |   1073741824 and maximum of 2147483647, and for negative values on the in-|
+ |   terval with minimum of -2147483648 and maximum of -1073741824; in order |
+ |   to normalize the result, the following operation must be done :         |
+ |                   norm_L_var1 = L_shl(L_var1,norm_l(L_var1)).             |
+ |                                                                           |
+ |   Complexity weight : 30                                                  |
+ |                                                                           |
+ |   Inputs :                                                                |
+ |                                                                           |
+ |    L_var1                                                                 |
+ |             32 bit long signed integer (Word32) whose value falls in the  |
+ |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
+ |                                                                           |
+ |   Outputs :                                                               |
+ |                                                                           |
+ |    none                                                                   |
+ |                                                                           |
+ |   Return Value :                                                          |
+ |                                                                           |
+ |    var_out                                                                |
+ |             16 bit short signed integer (Word16) whose value falls in the |
+ |             range : 0x0000 0000 <= var_out <= 0x0000 001f.                |
+ |___________________________________________________________________________|
+*/
+
+#if (!NORM_L_IS_INLINE)
+Word16 norm_l (Word32 L_var1)
+{
+    Word16 var_out;
+
+    if (L_var1 == 0)
+    {
+        var_out = 0;
+    }
+    else
+    {
+        if (L_var1 == (Word32) 0xffffffffL)
+        {
+            var_out = 31;
+        }
+        else
+        {
+            if (L_var1 < 0)
+            {
+                L_var1 = ~L_var1;
+            }
+            for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
+            {
+                L_var1 <<= 1;
+            }
+        }
+    }
+
+    return (var_out);
+}
+#endif
 
diff --git a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
index 906a9df..0ad82f0b 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
+++ b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		oper_32b.c

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		oper_32b.c
+
 	Content:	  This file contains operations in double precision.
- 

+ 
 *******************************************************************************/
 
 #include "typedef.h"
@@ -198,164 +198,164 @@
 
     return (L_32);
 }
-

-/*!

- 

-  \brief  calculates the log dualis times 4 of argument 

-          iLog4(x) = (Word32)(4 * log(value)/log(2.0))

-

-  \return ilog4 value

- 

-*/

-Word16 iLog4(Word32 value)

-{

-  Word16 iLog4;

-

-  if(value != 0){

-    Word32 tmp;

-    Word16 tmp16;

-    iLog4 = norm_l(value);

-    tmp = (value << iLog4);

-    tmp16 = round16(tmp);

-    tmp = L_mult(tmp16, tmp16);

-    tmp16 = round16(tmp);

-    tmp = L_mult(tmp16, tmp16);

-    tmp16 = round16(tmp);

-

-    iLog4 = (-(iLog4 << 2) - norm_s(tmp16)) - 1;

-  }

-  else {

-    iLog4 = -128; /* -(INT_BITS*4); */                                          

-  }

-

-  return iLog4;

-}

-

-#define step(shift) \

-    if ((0x40000000l >> shift) + root <= value)       \

-    {                                                 \

-        value -= (0x40000000l >> shift) + root;       \

-        root = (root >> 1) | (0x40000000l >> shift);  \

-    } else {                                          \

-        root = root >> 1;                             \

-    }

-

-Word32 rsqrt(Word32 value,     /*!< Operand to square root (0.0 ... 1) */

-             Word32 accuracy)  /*!< Number of valid bits that will be calculated */

-{

-    Word32 root = 0;

-	Word32 scale;

-

-	if(value < 0)

-		return 0;

-

-	scale = norm_l(value);

-	if(scale & 1) scale--;

-

-	value <<= scale;

-

-	step( 0); step( 2); step( 4); step( 6);

-    step( 8); step(10); step(12); step(14);

-    step(16); step(18); step(20); step(22);

-    step(24); step(26); step(28); step(30);

-

-    scale >>= 1;

-	if (root < value)

-        ++root;

-

-	root >>= scale;

-    return root* 46334;

-}

-

-static const Word32 pow2Table[POW2_TABLE_SIZE] = {

-0x7fffffff, 0x7fa765ad, 0x7f4f08ae, 0x7ef6e8da, 

-0x7e9f0606, 0x7e476009, 0x7deff6b6, 0x7d98c9e6, 

-0x7d41d96e, 0x7ceb2523, 0x7c94acde, 0x7c3e7073, 

-0x7be86fb9, 0x7b92aa88, 0x7b3d20b6, 0x7ae7d21a, 

-0x7a92be8b, 0x7a3de5df, 0x79e947ef, 0x7994e492, 

-0x7940bb9e, 0x78ecccec, 0x78991854, 0x78459dac, 

-0x77f25cce, 0x779f5591, 0x774c87cc, 0x76f9f359, 

-0x76a7980f, 0x765575c8, 0x76038c5b, 0x75b1dba2, 

-0x75606374, 0x750f23ab, 0x74be1c20, 0x746d4cac, 

-0x741cb528, 0x73cc556d, 0x737c2d55, 0x732c3cba, 

-0x72dc8374, 0x728d015d, 0x723db650, 0x71eea226, 

-0x719fc4b9, 0x71511de4, 0x7102ad80, 0x70b47368, 

-0x70666f76, 0x7018a185, 0x6fcb096f, 0x6f7da710, 

-0x6f307a41, 0x6ee382de, 0x6e96c0c3, 0x6e4a33c9, 

-0x6dfddbcc, 0x6db1b8a8, 0x6d65ca38, 0x6d1a1057, 

-0x6cce8ae1, 0x6c8339b2, 0x6c381ca6, 0x6bed3398, 

-0x6ba27e66, 0x6b57fce9, 0x6b0daeff, 0x6ac39485, 

-0x6a79ad56, 0x6a2ff94f, 0x69e6784d, 0x699d2a2c, 

-0x69540ec9, 0x690b2601, 0x68c26fb1, 0x6879ebb6, 

-0x683199ed, 0x67e97a34, 0x67a18c68, 0x6759d065, 

-0x6712460b, 0x66caed35, 0x6683c5c3, 0x663ccf92, 

-0x65f60a80, 0x65af766a, 0x6569132f, 0x6522e0ad, 

-0x64dcdec3, 0x64970d4f, 0x64516c2e, 0x640bfb41, 

-0x63c6ba64, 0x6381a978, 0x633cc85b, 0x62f816eb, 

-0x62b39509, 0x626f4292, 0x622b1f66, 0x61e72b65, 

-0x61a3666d, 0x615fd05f, 0x611c6919, 0x60d9307b, 

-0x60962665, 0x60534ab7, 0x60109d51, 0x5fce1e12, 

-0x5f8bccdb, 0x5f49a98c, 0x5f07b405, 0x5ec5ec26, 

-0x5e8451d0, 0x5e42e4e3, 0x5e01a540, 0x5dc092c7, 

-0x5d7fad59, 0x5d3ef4d7, 0x5cfe6923, 0x5cbe0a1c, 

-0x5c7dd7a4, 0x5c3dd19c, 0x5bfdf7e5, 0x5bbe4a61, 

-0x5b7ec8f2, 0x5b3f7377, 0x5b0049d4, 0x5ac14bea, 

-0x5a82799a, 0x5a43d2c6, 0x5a055751, 0x59c7071c, 

-0x5988e209, 0x594ae7fb, 0x590d18d3, 0x58cf7474, 

-0x5891fac1, 0x5854ab9b, 0x581786e6, 0x57da8c83, 

-0x579dbc57, 0x57611642, 0x57249a29, 0x56e847ef, 

-0x56ac1f75, 0x567020a0, 0x56344b52, 0x55f89f70, 

-0x55bd1cdb, 0x5581c378, 0x55469329, 0x550b8bd4, 

-0x54d0ad5b, 0x5495f7a1, 0x545b6a8b, 0x542105fd, 

-0x53e6c9db, 0x53acb607, 0x5372ca68, 0x533906e0, 

-0x52ff6b55, 0x52c5f7aa, 0x528cabc3, 0x52538786, 

-0x521a8ad7, 0x51e1b59a, 0x51a907b4, 0x5170810b, 

-0x51382182, 0x50ffe8fe, 0x50c7d765, 0x508fec9c, 

-0x50582888, 0x50208b0e, 0x4fe91413, 0x4fb1c37c, 

-0x4f7a9930, 0x4f439514, 0x4f0cb70c, 0x4ed5ff00, 

-0x4e9f6cd4, 0x4e69006e, 0x4e32b9b4, 0x4dfc988c, 

-0x4dc69cdd, 0x4d90c68b, 0x4d5b157e, 0x4d25899c, 

-0x4cf022ca, 0x4cbae0ef, 0x4c85c3f1, 0x4c50cbb8, 

-0x4c1bf829, 0x4be7492b, 0x4bb2bea5, 0x4b7e587d, 

-0x4b4a169c, 0x4b15f8e6, 0x4ae1ff43, 0x4aae299b, 

-0x4a7a77d5, 0x4a46e9d6, 0x4a137f88, 0x49e038d0, 

-0x49ad1598, 0x497a15c4, 0x4947393f, 0x49147fee, 

-0x48e1e9ba, 0x48af768a, 0x487d2646, 0x484af8d6, 

-0x4818ee22, 0x47e70611, 0x47b5408c, 0x47839d7b, 

-0x47521cc6, 0x4720be55, 0x46ef8210, 0x46be67e0, 

-0x468d6fae, 0x465c9961, 0x462be4e2, 0x45fb521a, 

-0x45cae0f2, 0x459a9152, 0x456a6323, 0x453a564d, 

-0x450a6abb, 0x44daa054, 0x44aaf702, 0x447b6ead, 

-0x444c0740, 0x441cc0a3, 0x43ed9ac0, 0x43be9580, 

-0x438fb0cb, 0x4360ec8d, 0x433248ae, 0x4303c517, 

-0x42d561b4, 0x42a71e6c, 0x4278fb2b, 0x424af7da, 

-0x421d1462, 0x41ef50ae, 0x41c1aca8, 0x41942839, 

-0x4166c34c, 0x41397dcc, 0x410c57a2, 0x40df50b8, 

-0x40b268fa, 0x4085a051, 0x4058f6a8, 0x402c6be9 

-};

-

-/*!

- 

-  \brief calculates 2 ^ (x/y) for x<=0, y > 0, x <= 32768 * y 

-  

-  avoids integer division

-  

-  \return 

-*/

-Word32 pow2_xy(Word32 x, Word32 y)

-{

-  Word32 iPart;

-  Word32 fPart;

-  Word32 res;

-  Word32 tmp, tmp2;

-  Word32 shift, shift2;

-

-  tmp2 = -x;

-  iPart = tmp2 / y;

-  fPart = tmp2 - iPart*y;

-  iPart = min(iPart,INT_BITS-1);

-

-  res = pow2Table[(POW2_TABLE_SIZE*fPart)/y] >> iPart; 

- 

-  return(res);

+
+/*!
+ 
+  \brief  calculates the log dualis times 4 of argument 
+          iLog4(x) = (Word32)(4 * log(value)/log(2.0))
+
+  \return ilog4 value
+ 
+*/
+Word16 iLog4(Word32 value)
+{
+  Word16 iLog4;
+
+  if(value != 0){
+    Word32 tmp;
+    Word16 tmp16;
+    iLog4 = norm_l(value);
+    tmp = (value << iLog4);
+    tmp16 = round16(tmp);
+    tmp = L_mult(tmp16, tmp16);
+    tmp16 = round16(tmp);
+    tmp = L_mult(tmp16, tmp16);
+    tmp16 = round16(tmp);
+
+    iLog4 = (-(iLog4 << 2) - norm_s(tmp16)) - 1;
+  }
+  else {
+    iLog4 = -128; /* -(INT_BITS*4); */                                          
+  }
+
+  return iLog4;
+}
+
+#define step(shift) \
+    if ((0x40000000l >> shift) + root <= value)       \
+    {                                                 \
+        value -= (0x40000000l >> shift) + root;       \
+        root = (root >> 1) | (0x40000000l >> shift);  \
+    } else {                                          \
+        root = root >> 1;                             \
+    }
+
+Word32 rsqrt(Word32 value,     /*!< Operand to square root (0.0 ... 1) */
+             Word32 accuracy)  /*!< Number of valid bits that will be calculated */
+{
+    Word32 root = 0;
+	Word32 scale;
+
+	if(value < 0)
+		return 0;
+
+	scale = norm_l(value);
+	if(scale & 1) scale--;
+
+	value <<= scale;
+
+	step( 0); step( 2); step( 4); step( 6);
+    step( 8); step(10); step(12); step(14);
+    step(16); step(18); step(20); step(22);
+    step(24); step(26); step(28); step(30);
+
+    scale >>= 1;
+	if (root < value)
+        ++root;
+
+	root >>= scale;
+    return root* 46334;
+}
+
+static const Word32 pow2Table[POW2_TABLE_SIZE] = {
+0x7fffffff, 0x7fa765ad, 0x7f4f08ae, 0x7ef6e8da, 
+0x7e9f0606, 0x7e476009, 0x7deff6b6, 0x7d98c9e6, 
+0x7d41d96e, 0x7ceb2523, 0x7c94acde, 0x7c3e7073, 
+0x7be86fb9, 0x7b92aa88, 0x7b3d20b6, 0x7ae7d21a, 
+0x7a92be8b, 0x7a3de5df, 0x79e947ef, 0x7994e492, 
+0x7940bb9e, 0x78ecccec, 0x78991854, 0x78459dac, 
+0x77f25cce, 0x779f5591, 0x774c87cc, 0x76f9f359, 
+0x76a7980f, 0x765575c8, 0x76038c5b, 0x75b1dba2, 
+0x75606374, 0x750f23ab, 0x74be1c20, 0x746d4cac, 
+0x741cb528, 0x73cc556d, 0x737c2d55, 0x732c3cba, 
+0x72dc8374, 0x728d015d, 0x723db650, 0x71eea226, 
+0x719fc4b9, 0x71511de4, 0x7102ad80, 0x70b47368, 
+0x70666f76, 0x7018a185, 0x6fcb096f, 0x6f7da710, 
+0x6f307a41, 0x6ee382de, 0x6e96c0c3, 0x6e4a33c9, 
+0x6dfddbcc, 0x6db1b8a8, 0x6d65ca38, 0x6d1a1057, 
+0x6cce8ae1, 0x6c8339b2, 0x6c381ca6, 0x6bed3398, 
+0x6ba27e66, 0x6b57fce9, 0x6b0daeff, 0x6ac39485, 
+0x6a79ad56, 0x6a2ff94f, 0x69e6784d, 0x699d2a2c, 
+0x69540ec9, 0x690b2601, 0x68c26fb1, 0x6879ebb6, 
+0x683199ed, 0x67e97a34, 0x67a18c68, 0x6759d065, 
+0x6712460b, 0x66caed35, 0x6683c5c3, 0x663ccf92, 
+0x65f60a80, 0x65af766a, 0x6569132f, 0x6522e0ad, 
+0x64dcdec3, 0x64970d4f, 0x64516c2e, 0x640bfb41, 
+0x63c6ba64, 0x6381a978, 0x633cc85b, 0x62f816eb, 
+0x62b39509, 0x626f4292, 0x622b1f66, 0x61e72b65, 
+0x61a3666d, 0x615fd05f, 0x611c6919, 0x60d9307b, 
+0x60962665, 0x60534ab7, 0x60109d51, 0x5fce1e12, 
+0x5f8bccdb, 0x5f49a98c, 0x5f07b405, 0x5ec5ec26, 
+0x5e8451d0, 0x5e42e4e3, 0x5e01a540, 0x5dc092c7, 
+0x5d7fad59, 0x5d3ef4d7, 0x5cfe6923, 0x5cbe0a1c, 
+0x5c7dd7a4, 0x5c3dd19c, 0x5bfdf7e5, 0x5bbe4a61, 
+0x5b7ec8f2, 0x5b3f7377, 0x5b0049d4, 0x5ac14bea, 
+0x5a82799a, 0x5a43d2c6, 0x5a055751, 0x59c7071c, 
+0x5988e209, 0x594ae7fb, 0x590d18d3, 0x58cf7474, 
+0x5891fac1, 0x5854ab9b, 0x581786e6, 0x57da8c83, 
+0x579dbc57, 0x57611642, 0x57249a29, 0x56e847ef, 
+0x56ac1f75, 0x567020a0, 0x56344b52, 0x55f89f70, 
+0x55bd1cdb, 0x5581c378, 0x55469329, 0x550b8bd4, 
+0x54d0ad5b, 0x5495f7a1, 0x545b6a8b, 0x542105fd, 
+0x53e6c9db, 0x53acb607, 0x5372ca68, 0x533906e0, 
+0x52ff6b55, 0x52c5f7aa, 0x528cabc3, 0x52538786, 
+0x521a8ad7, 0x51e1b59a, 0x51a907b4, 0x5170810b, 
+0x51382182, 0x50ffe8fe, 0x50c7d765, 0x508fec9c, 
+0x50582888, 0x50208b0e, 0x4fe91413, 0x4fb1c37c, 
+0x4f7a9930, 0x4f439514, 0x4f0cb70c, 0x4ed5ff00, 
+0x4e9f6cd4, 0x4e69006e, 0x4e32b9b4, 0x4dfc988c, 
+0x4dc69cdd, 0x4d90c68b, 0x4d5b157e, 0x4d25899c, 
+0x4cf022ca, 0x4cbae0ef, 0x4c85c3f1, 0x4c50cbb8, 
+0x4c1bf829, 0x4be7492b, 0x4bb2bea5, 0x4b7e587d, 
+0x4b4a169c, 0x4b15f8e6, 0x4ae1ff43, 0x4aae299b, 
+0x4a7a77d5, 0x4a46e9d6, 0x4a137f88, 0x49e038d0, 
+0x49ad1598, 0x497a15c4, 0x4947393f, 0x49147fee, 
+0x48e1e9ba, 0x48af768a, 0x487d2646, 0x484af8d6, 
+0x4818ee22, 0x47e70611, 0x47b5408c, 0x47839d7b, 
+0x47521cc6, 0x4720be55, 0x46ef8210, 0x46be67e0, 
+0x468d6fae, 0x465c9961, 0x462be4e2, 0x45fb521a, 
+0x45cae0f2, 0x459a9152, 0x456a6323, 0x453a564d, 
+0x450a6abb, 0x44daa054, 0x44aaf702, 0x447b6ead, 
+0x444c0740, 0x441cc0a3, 0x43ed9ac0, 0x43be9580, 
+0x438fb0cb, 0x4360ec8d, 0x433248ae, 0x4303c517, 
+0x42d561b4, 0x42a71e6c, 0x4278fb2b, 0x424af7da, 
+0x421d1462, 0x41ef50ae, 0x41c1aca8, 0x41942839, 
+0x4166c34c, 0x41397dcc, 0x410c57a2, 0x40df50b8, 
+0x40b268fa, 0x4085a051, 0x4058f6a8, 0x402c6be9 
+};
+
+/*!
+ 
+  \brief calculates 2 ^ (x/y) for x<=0, y > 0, x <= 32768 * y 
+  
+  avoids integer division
+  
+  \return 
+*/
+Word32 pow2_xy(Word32 x, Word32 y)
+{
+  Word32 iPart;
+  Word32 fPart;
+  Word32 res;
+  Word32 tmp, tmp2;
+  Word32 shift, shift2;
+
+  tmp2 = -x;
+  iPart = tmp2 / y;
+  fPart = tmp2 - iPart*y;
+  iPart = min(iPart,INT_BITS-1);
+
+  res = pow2Table[(POW2_TABLE_SIZE*fPart)/y] >> iPart; 
+ 
+  return(res);
 }
\ No newline at end of file
diff --git a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h
index 4119bc3..1d35e5e 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h
@@ -1,86 +1,86 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		oper_32b.h

-

-	Content:	Double precision operations

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		oper_32b.h
+
+	Content:	Double precision operations
+
 *******************************************************************************/
 
 #ifndef __OPER_32b_H
 #define __OPER_32b_H
-

-#include "typedef.h"

+
+#include "typedef.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
-

-#define POW2_TABLE_BITS 8

-#define POW2_TABLE_SIZE (1<<POW2_TABLE_BITS)

+
+#define POW2_TABLE_BITS 8
+#define POW2_TABLE_SIZE (1<<POW2_TABLE_BITS)
 
 void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo);
 Word32 L_Comp (Word16 hi, Word16 lo);
 Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2);
 Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n);
 Word32 Div_32 (Word32 L_num, Word32 denom);
-Word16 iLog4(Word32 value);

-Word32 rsqrt(Word32 value,  Word32 accuracy);

-Word32 pow2_xy(Word32 x, Word32 y);

-

-__inline Word32 L_mpy_ls(Word32 L_var2, Word16 var1)

-{

-    unsigned short swLow1;

-    Word16 swHigh1;

-    Word32 l_var_out;

-

-    swLow1 = (unsigned short)(L_var2);

-    swHigh1 = (Word16)(L_var2 >> 16);

-

-    l_var_out = (long)swLow1 * (long)var1 >> 15;

-    

-    l_var_out += swHigh1 * var1 << 1;

-    

-    return(l_var_out);

-}

-

-__inline Word32 L_mpy_wx(Word32 L_var2, Word16 var1)

-{

-#if ARMV5TE_L_MPY_LS

-	Word32 result; 

-	asm volatile( 

-		"SMULWB  %[result], %[L_var2], %[var1] \n" 

-		:[result]"+r"(result)

-		:[L_var2]"r"(L_var2), [var1]"r"(var1)

-		); 

-	return result;

-#else

-    unsigned short swLow1;

-    Word16 swHigh1;

-    Word32 l_var_out;

-

-    swLow1 = (unsigned short)(L_var2);

-    swHigh1 = (Word16)(L_var2 >> 16);

-

-    l_var_out = (long)swLow1 * (long)var1 >> 16;    

-    l_var_out += swHigh1 * var1;

-    

-    return(l_var_out);

-#endif

-}

+Word16 iLog4(Word32 value);
+Word32 rsqrt(Word32 value,  Word32 accuracy);
+Word32 pow2_xy(Word32 x, Word32 y);
+
+__inline Word32 L_mpy_ls(Word32 L_var2, Word16 var1)
+{
+    unsigned short swLow1;
+    Word16 swHigh1;
+    Word32 l_var_out;
+
+    swLow1 = (unsigned short)(L_var2);
+    swHigh1 = (Word16)(L_var2 >> 16);
+
+    l_var_out = (long)swLow1 * (long)var1 >> 15;
+    
+    l_var_out += swHigh1 * var1 << 1;
+    
+    return(l_var_out);
+}
+
+__inline Word32 L_mpy_wx(Word32 L_var2, Word16 var1)
+{
+#if ARMV5TE_L_MPY_LS
+	Word32 result; 
+	asm volatile( 
+		"SMULWB  %[result], %[L_var2], %[var1] \n" 
+		:[result]"+r"(result)
+		:[L_var2]"r"(L_var2), [var1]"r"(var1)
+		); 
+	return result;
+#else
+    unsigned short swLow1;
+    Word16 swHigh1;
+    Word32 l_var_out;
+
+    swLow1 = (unsigned short)(L_var2);
+    swHigh1 = (Word16)(L_var2 >> 16);
+
+    l_var_out = (long)swLow1 * (long)var1 >> 16;    
+    l_var_out += swHigh1 * var1;
+    
+    return(l_var_out);
+#endif
+}
 
 #ifdef __cplusplus
 }
diff --git a/media/libstagefright/codecs/aacenc/basic_op/typedef.h b/media/libstagefright/codecs/aacenc/basic_op/typedef.h
index d3a626a..1030803 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/typedef.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/typedef.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		typedef.h

-

-	Content:	type defined for defferent paltform

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		typedef.h
+
+	Content:	type defined for defferent paltform
+
 *******************************************************************************/
 
 #ifndef typedef_h
@@ -54,7 +54,7 @@
 
 /*
  * use (improved) type definition file typdefs.h and add a "Flag" type
- */

+ */
 #include "typedefs.h"
 typedef int Flag;
 
diff --git a/media/libstagefright/codecs/aacenc/basic_op/typedefs.h b/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
index 7d16fca..c7e774b 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
@@ -1,56 +1,56 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		typedefs.h

-

-	Content:	type defined or const defined

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		typedefs.h
+
+	Content:	type defined or const defined
+
 *******************************************************************************/
 
 #ifndef typedefs_h
 #define typedefs_h "$Id $"
 
-#ifndef CHAR_BIT

-#define CHAR_BIT      8         /* number of bits in a char */

-#endif

-

-#ifndef VOAAC_SHRT_MAX

-#define VOAAC_SHRT_MAX    (32767)        /* maximum (signed) short value */

-#endif

+#ifndef CHAR_BIT
+#define CHAR_BIT      8         /* number of bits in a char */
+#endif
 
-#ifndef VOAAC_SHRT_MIN

-#define VOAAC_SHRT_MIN    (-32768)        /* minimum (signed) short value */

-#endif

+#ifndef VOAAC_SHRT_MAX
+#define VOAAC_SHRT_MAX    (32767)        /* maximum (signed) short value */
+#endif
 
-/* Define NULL pointer value */

-#ifndef NULL

-#ifdef __cplusplus

-#define NULL    0

-#else

-#define NULL    ((void *)0)

-#endif

+#ifndef VOAAC_SHRT_MIN
+#define VOAAC_SHRT_MIN    (-32768)        /* minimum (signed) short value */
+#endif
+
+/* Define NULL pointer value */
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL    0
+#else
+#define NULL    ((void *)0)
+#endif
 #endif
 
 #ifndef assert
 #define assert(_Expression)     ((void)0)
 #endif
-

-#ifdef LINUX

-#define __inline static __inline__

-#endif

+
+#ifdef LINUX
+#define __inline static __inline__
+#endif
 
 #define INT_BITS   32
 /*
@@ -80,100 +80,100 @@
 typedef long Word32;
 typedef unsigned long UWord32;
 
-

-

+
+
 #ifdef LINUX
 typedef long long Word64;
 typedef unsigned long long UWord64;
 #else
-typedef __int64 Word64;

+typedef __int64 Word64;
 typedef unsigned __int64 UWord64;
 #endif
 
-#ifndef min

-#define min(a,b) ( a < b ? a : b)

-#endif

-

-#ifndef max

-#define max(a,b) ( a > b ? a : b)

-#endif

-

-#ifdef ARM_INASM

-#ifdef ARMV5_INASM

-#define ARMV5E_INASM	1

-#endif

-#define ARMV4_INASM		1

-#endif

-
-#if ARMV4_INASM

-	#define ARMV5TE_SAT           1

-    #define ARMV5TE_ADD           1

-    #define ARMV5TE_SUB           1

-	#define ARMV5TE_SHL           1

-    #define ARMV5TE_SHR           1

-	#define ARMV5TE_L_SHL         1

-    #define ARMV5TE_L_SHR         1

-#endif//ARMV4

-#if ARMV5E_INASM

-    #define ARMV5TE_L_ADD         1

-    #define ARMV5TE_L_SUB         1

-    #define ARMV5TE_L_MULT        1

-    #define ARMV5TE_L_MAC         1

-    #define ARMV5TE_L_MSU         1

-   

-    

-    #define ARMV5TE_DIV_S         1

-    #define ARMV5TE_ROUND         1

-    #define ARMV5TE_MULT          1

-    

-    #define ARMV5TE_NORM_S        1

-    #define ARMV5TE_NORM_L        1

-	#define ARMV5TE_L_MPY_LS	  1

+#ifndef min
+#define min(a,b) ( a < b ? a : b)
 #endif
-

-//basic operation functions optimization flags

-#define SATRUATE_IS_INLINE              1   //define saturate as inline function

-#define SHL_IS_INLINE                   1  //define shl as inline function

-#define SHR_IS_INLINE                   1   //define shr as inline function

-#define L_MULT_IS_INLINE                1   //define L_mult as inline function

-#define L_MSU_IS_INLINE                 1   //define L_msu as inline function

-#define L_SUB_IS_INLINE                 1   //define L_sub as inline function

-#define L_SHL_IS_INLINE                 1   //define L_shl as inline function

-#define L_SHR_IS_INLINE                 1   //define L_shr as inline function

-#define ADD_IS_INLINE                   1   //define add as inline function //add, inline is the best

-#define SUB_IS_INLINE                   1   //define sub as inline function //sub, inline is the best

-#define DIV_S_IS_INLINE                 1   //define div_s as inline function

-#define MULT_IS_INLINE                  1   //define mult as inline function

-#define NORM_S_IS_INLINE                1   //define norm_s as inline function

-#define NORM_L_IS_INLINE                1   //define norm_l as inline function

-#define ROUND_IS_INLINE                 1   //define round as inline function

-#define L_MAC_IS_INLINE                 1   //define L_mac as inline function

-#define L_ADD_IS_INLINE                 1   //define L_add as inline function

-#define EXTRACT_H_IS_INLINE             1   //define extract_h as inline function 

-#define EXTRACT_L_IS_INLINE             1   //define extract_l as inline function        //???

-#define MULT_R_IS_INLINE                1   //define mult_r as inline function

-#define SHR_R_IS_INLINE                 1   //define shr_r as inline function

-#define MAC_R_IS_INLINE                 1   //define mac_r as inline function

-#define MSU_R_IS_INLINE                 1   //define msu_r as inline function

-#define L_SHR_R_IS_INLINE               1   //define L_shr_r as inline function

-

-#define PREFIX				voAACEnc

-#define LINK0(x, y, z)		LINK1(x,y,z)

-#define LINK1(x,y,z)		x##y##z

-#define ADD_PREFIX(func)	LINK0(PREFIX, _, func)

-

-#define  L_Extract		ADD_PREFIX(L_Extract)

-#define  L_Comp			ADD_PREFIX(L_Comp)

-#define  Mpy_32			ADD_PREFIX(Mpy_32)

-#define  Mpy_32_16		ADD_PREFIX(Mpy_32_16)

-#define  Div_32			ADD_PREFIX(Div_32)

-#define  iLog4			ADD_PREFIX(iLog4)

-#define  rsqrt			ADD_PREFIX(rsqrt)

-#define  pow2_xy		ADD_PREFIX(pow2_xy)

-#define  L_mpy_ls		ADD_PREFIX(L_mpy_ls)

-#define  L_mpy_wx		ADD_PREFIX(L_mpy_wx)

-

-#define mem_malloc		ADD_PREFIX(mem_malloc)

-#define mem_free		ADD_PREFIX(mem_free)

-

+
+#ifndef max
+#define max(a,b) ( a > b ? a : b)
+#endif
+
+#ifdef ARM_INASM
+#ifdef ARMV5_INASM
+#define ARMV5E_INASM	1
+#endif
+#define ARMV4_INASM		1
+#endif
+
+#if ARMV4_INASM
+	#define ARMV5TE_SAT           1
+    #define ARMV5TE_ADD           1
+    #define ARMV5TE_SUB           1
+	#define ARMV5TE_SHL           1
+    #define ARMV5TE_SHR           1
+	#define ARMV5TE_L_SHL         1
+    #define ARMV5TE_L_SHR         1
+#endif//ARMV4
+#if ARMV5E_INASM
+    #define ARMV5TE_L_ADD         1
+    #define ARMV5TE_L_SUB         1
+    #define ARMV5TE_L_MULT        1
+    #define ARMV5TE_L_MAC         1
+    #define ARMV5TE_L_MSU         1
+   
+    
+    #define ARMV5TE_DIV_S         1
+    #define ARMV5TE_ROUND         1
+    #define ARMV5TE_MULT          1
+    
+    #define ARMV5TE_NORM_S        1
+    #define ARMV5TE_NORM_L        1
+	#define ARMV5TE_L_MPY_LS	  1
+#endif
+
+//basic operation functions optimization flags
+#define SATRUATE_IS_INLINE              1   //define saturate as inline function
+#define SHL_IS_INLINE                   1  //define shl as inline function
+#define SHR_IS_INLINE                   1   //define shr as inline function
+#define L_MULT_IS_INLINE                1   //define L_mult as inline function
+#define L_MSU_IS_INLINE                 1   //define L_msu as inline function
+#define L_SUB_IS_INLINE                 1   //define L_sub as inline function
+#define L_SHL_IS_INLINE                 1   //define L_shl as inline function
+#define L_SHR_IS_INLINE                 1   //define L_shr as inline function
+#define ADD_IS_INLINE                   1   //define add as inline function //add, inline is the best
+#define SUB_IS_INLINE                   1   //define sub as inline function //sub, inline is the best
+#define DIV_S_IS_INLINE                 1   //define div_s as inline function
+#define MULT_IS_INLINE                  1   //define mult as inline function
+#define NORM_S_IS_INLINE                1   //define norm_s as inline function
+#define NORM_L_IS_INLINE                1   //define norm_l as inline function
+#define ROUND_IS_INLINE                 1   //define round as inline function
+#define L_MAC_IS_INLINE                 1   //define L_mac as inline function
+#define L_ADD_IS_INLINE                 1   //define L_add as inline function
+#define EXTRACT_H_IS_INLINE             1   //define extract_h as inline function 
+#define EXTRACT_L_IS_INLINE             1   //define extract_l as inline function        //???
+#define MULT_R_IS_INLINE                1   //define mult_r as inline function
+#define SHR_R_IS_INLINE                 1   //define shr_r as inline function
+#define MAC_R_IS_INLINE                 1   //define mac_r as inline function
+#define MSU_R_IS_INLINE                 1   //define msu_r as inline function
+#define L_SHR_R_IS_INLINE               1   //define L_shr_r as inline function
+
+#define PREFIX				voAACEnc
+#define LINK0(x, y, z)		LINK1(x,y,z)
+#define LINK1(x,y,z)		x##y##z
+#define ADD_PREFIX(func)	LINK0(PREFIX, _, func)
+
+#define  L_Extract		ADD_PREFIX(L_Extract)
+#define  L_Comp			ADD_PREFIX(L_Comp)
+#define  Mpy_32			ADD_PREFIX(Mpy_32)
+#define  Mpy_32_16		ADD_PREFIX(Mpy_32_16)
+#define  Div_32			ADD_PREFIX(Div_32)
+#define  iLog4			ADD_PREFIX(iLog4)
+#define  rsqrt			ADD_PREFIX(rsqrt)
+#define  pow2_xy		ADD_PREFIX(pow2_xy)
+#define  L_mpy_ls		ADD_PREFIX(L_mpy_ls)
+#define  L_mpy_wx		ADD_PREFIX(L_mpy_wx)
+
+#define mem_malloc		ADD_PREFIX(mem_malloc)
+#define mem_free		ADD_PREFIX(mem_free)
+
 #endif
diff --git a/media/libstagefright/codecs/aacenc/build/eclair/ARMV5E/Makefile b/media/libstagefright/codecs/aacenc/build/eclair/ARMV5E/Makefile
index b4f63af..2464f1b 100644
--- a/media/libstagefright/codecs/aacenc/build/eclair/ARMV5E/Makefile
+++ b/media/libstagefright/codecs/aacenc/build/eclair/ARMV5E/Makefile
@@ -1,55 +1,55 @@
-#/*

-#** Copyright 2003-2010, VisualOn, Inc.

-#**

-#** Licensed under the Apache License, Version 2.0 (the "License");

-#** you may not use this file except in compliance with the License.

-#** You may obtain a copy of the License at

-#**

-#**     http://www.apache.org/licenses/LICENSE-2.0

-#**

-#** Unless required by applicable law or agreed to in writing, software

-#** distributed under the License is distributed on an "AS IS" BASIS,

-#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

-#** See the License for the specific language governing permissions and

-#** limitations under the License.

-#*/

-

-# target6

-# available: pc, v4(armv4), v5(armv5), v5x(armv5 xscale), v6(armv6), v7(cortex-a8 neon)

-VOTT:= v5

-

-

-# module type

-# please specify the type of your module: lib or exe

-VOMT:= lib

-

-

-# module macros

-# please append the additional macro definitions here for your module if necessary. 

-# e.g. -DVISUALON, macro VISUALON defined for your module 

-VOMM:= -DARMV5E -DARM_INASM -DARMV5_INASM 

-

-

-

-# please specify the name of your module

-VOTARGET:=libvoAACEncv5

-

-

-# please modify here to be sure to see the g1.mk

-include ../../../../../Tools/eclair.mk 

-

-# dependent libraries.

-VODEPLIBS:=#-ldl -lstdc++ 

-

-# module source

-# please modify here to be sure to see the ms.mk which specifies all source info of your module

-include ../../ms.mk

-

-

-# please specify where is the voRelease on your PC, relative path is suggested

-VORELDIR:=../../../../../../Release

-

-

-# please modify here to be sure to see the doit.mk

-include ../../../../../Tools/doit.mk 

-

+#/*
+#** Copyright 2003-2010, VisualOn, Inc.
+#**
+#** Licensed under the Apache License, Version 2.0 (the "License");
+#** you may not use this file except in compliance with the License.
+#** You may obtain a copy of the License at
+#**
+#**     http://www.apache.org/licenses/LICENSE-2.0
+#**
+#** Unless required by applicable law or agreed to in writing, software
+#** distributed under the License is distributed on an "AS IS" BASIS,
+#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#** See the License for the specific language governing permissions and
+#** limitations under the License.
+#*/
+
+# target6
+# available: pc, v4(armv4), v5(armv5), v5x(armv5 xscale), v6(armv6), v7(cortex-a8 neon)
+VOTT:= v5
+
+
+# module type
+# please specify the type of your module: lib or exe
+VOMT:= lib
+
+
+# module macros
+# please append the additional macro definitions here for your module if necessary. 
+# e.g. -DVISUALON, macro VISUALON defined for your module 
+VOMM:= -DARMV5E -DARM_INASM -DARMV5_INASM 
+
+
+
+# please specify the name of your module
+VOTARGET:=libvoAACEncv5
+
+
+# please modify here to be sure to see the g1.mk
+include ../../../../../Tools/eclair.mk 
+
+# dependent libraries.
+VODEPLIBS:=#-ldl -lstdc++ 
+
+# module source
+# please modify here to be sure to see the ms.mk which specifies all source info of your module
+include ../../ms.mk
+
+
+# please specify where is the voRelease on your PC, relative path is suggested
+VORELDIR:=../../../../../../Release
+
+
+# please modify here to be sure to see the doit.mk
+include ../../../../../Tools/doit.mk 
+
diff --git a/media/libstagefright/codecs/aacenc/build/eclair/ARMV7/Makefile b/media/libstagefright/codecs/aacenc/build/eclair/ARMV7/Makefile
index cdce2c1..23c51cb 100644
--- a/media/libstagefright/codecs/aacenc/build/eclair/ARMV7/Makefile
+++ b/media/libstagefright/codecs/aacenc/build/eclair/ARMV7/Makefile
@@ -1,55 +1,55 @@
-#/*

-#** Copyright 2003-2010, VisualOn, Inc.

-#**

-#** Licensed under the Apache License, Version 2.0 (the "License");

-#** you may not use this file except in compliance with the License.

-#** You may obtain a copy of the License at

-#**

-#**     http://www.apache.org/licenses/LICENSE-2.0

-#**

-#** Unless required by applicable law or agreed to in writing, software

-#** distributed under the License is distributed on an "AS IS" BASIS,

-#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

-#** See the License for the specific language governing permissions and

-#** limitations under the License.

-#*/

-

-# target6

-# available: pc, v4(armv4), v5(armv5), v5x(armv5 xscale), v6(armv6), v7(cortex-a8 neon)

-VOTT:= v7

-

-

-# module type

-# please specify the type of your module: lib or exe

-VOMT:= lib

-

-

-# module macros

-# please append the additional macro definitions here for your module if necessary. 

-# e.g. -DVISUALON, macro VISUALON defined for your module 

-VOMM:= -DARMV5E -DARMV7Neon -DARM_INASM -DARMV5_INASM 

-

-

-

-# please specify the name of your module

-VOTARGET:=libvoAACEncv7

-

-

-# please modify here to be sure to see the g1.mk

-include ../../../../../Tools/eclair.mk 

-

-# dependent libraries.

-VODEPLIBS:=#-ldl -lstdc++ 

-

-# module source

-# please modify here to be sure to see the ms.mk which specifies all source info of your module

-include ../../ms.mk

-

-

-# please specify where is the voRelease on your PC, relative path is suggested

-VORELDIR:=../../../../../../Release

-

-

-# please modify here to be sure to see the doit.mk

-include ../../../../../Tools/doit.mk  

-

+#/*
+#** Copyright 2003-2010, VisualOn, Inc.
+#**
+#** Licensed under the Apache License, Version 2.0 (the "License");
+#** you may not use this file except in compliance with the License.
+#** You may obtain a copy of the License at
+#**
+#**     http://www.apache.org/licenses/LICENSE-2.0
+#**
+#** Unless required by applicable law or agreed to in writing, software
+#** distributed under the License is distributed on an "AS IS" BASIS,
+#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#** See the License for the specific language governing permissions and
+#** limitations under the License.
+#*/
+
+# target6
+# available: pc, v4(armv4), v5(armv5), v5x(armv5 xscale), v6(armv6), v7(cortex-a8 neon)
+VOTT:= v7
+
+
+# module type
+# please specify the type of your module: lib or exe
+VOMT:= lib
+
+
+# module macros
+# please append the additional macro definitions here for your module if necessary. 
+# e.g. -DVISUALON, macro VISUALON defined for your module 
+VOMM:= -DARMV5E -DARMV7Neon -DARM_INASM -DARMV5_INASM 
+
+
+
+# please specify the name of your module
+VOTARGET:=libvoAACEncv7
+
+
+# please modify here to be sure to see the g1.mk
+include ../../../../../Tools/eclair.mk 
+
+# dependent libraries.
+VODEPLIBS:=#-ldl -lstdc++ 
+
+# module source
+# please modify here to be sure to see the ms.mk which specifies all source info of your module
+include ../../ms.mk
+
+
+# please specify where is the voRelease on your PC, relative path is suggested
+VORELDIR:=../../../../../../Release
+
+
+# please modify here to be sure to see the doit.mk
+include ../../../../../Tools/doit.mk  
+
diff --git a/media/libstagefright/codecs/aacenc/build/ms.mk b/media/libstagefright/codecs/aacenc/build/ms.mk
index b67efbc..fcd9bb3 100644
--- a/media/libstagefright/codecs/aacenc/build/ms.mk
+++ b/media/libstagefright/codecs/aacenc/build/ms.mk
@@ -1,42 +1,42 @@
-#/*

-#** Copyright 2003-2010, VisualOn, Inc.

-#**

-#** Licensed under the Apache License, Version 2.0 (the "License");

-#** you may not use this file except in compliance with the License.

-#** You may obtain a copy of the License at

-#**

-#**     http://www.apache.org/licenses/LICENSE-2.0

-#**

-#** Unless required by applicable law or agreed to in writing, software

-#** distributed under the License is distributed on an "AS IS" BASIS,

-#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

-#** See the License for the specific language governing permissions and

-#** limitations under the License.

-#*/

-

-

-# please list all objects needed by your target here

-OBJS:=basicop2.o oper_32b.o aac_rom.o aacenc.o aacenc_core.o adj_thr.o \

-			band_nrg.o bit_cnt.o bitbuffer.o bitenc.o block_switch.o channel_map.o \

-			dyn_bits.o grp_data.o interface.o line_pe.o memalign.o ms_stereo.o \

-			pre_echo_control.o psy_configuration.o psy_main.o qc_main.o quantize.o sf_estim.o \

-			spreading.o stat_bits.o tns.o transform.o

-			

-# please list all directories that all source files relative with your module(.h .c .cpp) locate 

-VOSRCDIR:=../../../src \

-					../../../inc \

-					../../../basic_op\

-					../../../../../Include 

-					

-ifeq ($(VOTT), v5)

-OBJS+= AutoCorrelation_v5.o band_nrg_v5.o CalcWindowEnergy_v5.o \

-				PrePostMDCT_v5.o R4R8First_v5.o Radix4FFT_v5.o

-VOSRCDIR+= ../../../src/asm/ARMV5E/

-endif	

-

-ifeq ($(VOTT), v7)

-OBJS+= AutoCorrelation_v5.o band_nrg_v5.o CalcWindowEnergy_v5.o \

-			 PrePostMDCT_v7.o R4R8First_v7.o Radix4FFT_v7.o

-VOSRCDIR+= ../../../src/asm/ARMV5E/

-VOSRCDIR+= ../../../src/asm/ARMV7/

+#/*
+#** Copyright 2003-2010, VisualOn, Inc.
+#**
+#** Licensed under the Apache License, Version 2.0 (the "License");
+#** you may not use this file except in compliance with the License.
+#** You may obtain a copy of the License at
+#**
+#**     http://www.apache.org/licenses/LICENSE-2.0
+#**
+#** Unless required by applicable law or agreed to in writing, software
+#** distributed under the License is distributed on an "AS IS" BASIS,
+#** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#** See the License for the specific language governing permissions and
+#** limitations under the License.
+#*/
+
+
+# please list all objects needed by your target here
+OBJS:=basicop2.o oper_32b.o aac_rom.o aacenc.o aacenc_core.o adj_thr.o \
+			band_nrg.o bit_cnt.o bitbuffer.o bitenc.o block_switch.o channel_map.o \
+			dyn_bits.o grp_data.o interface.o line_pe.o memalign.o ms_stereo.o \
+			pre_echo_control.o psy_configuration.o psy_main.o qc_main.o quantize.o sf_estim.o \
+			spreading.o stat_bits.o tns.o transform.o
+			
+# please list all directories that all source files relative with your module(.h .c .cpp) locate 
+VOSRCDIR:=../../../src \
+					../../../inc \
+					../../../basic_op\
+					../../../../../Include 
+					
+ifeq ($(VOTT), v5)
+OBJS+= AutoCorrelation_v5.o band_nrg_v5.o CalcWindowEnergy_v5.o \
+				PrePostMDCT_v5.o R4R8First_v5.o Radix4FFT_v5.o
+VOSRCDIR+= ../../../src/asm/ARMV5E/
+endif	
+
+ifeq ($(VOTT), v7)
+OBJS+= AutoCorrelation_v5.o band_nrg_v5.o CalcWindowEnergy_v5.o \
+			 PrePostMDCT_v7.o R4R8First_v7.o Radix4FFT_v7.o
+VOSRCDIR+= ../../../src/asm/ARMV5E/
+VOSRCDIR+= ../../../src/asm/ARMV7/
 endif		
\ No newline at end of file
diff --git a/media/libstagefright/codecs/aacenc/inc/aac_rom.h b/media/libstagefright/codecs/aacenc/inc/aac_rom.h
index b0429fc..784bb70 100644
--- a/media/libstagefright/codecs/aacenc/inc/aac_rom.h
+++ b/media/libstagefright/codecs/aacenc/inc/aac_rom.h
@@ -1,28 +1,28 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		aac_rom.h

-

-	Content:	constant tables 

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		aac_rom.h
+
+	Content:	constant tables 
+
 *******************************************************************************/
 
 #ifndef ROM_H
 #define ROM_H
-

+
 #include "config.h"
 #include "psy_const.h"
 #include "tns_param.h"
@@ -31,16 +31,16 @@
   mdct
 */
 extern const int ShortWindowSine[FRAME_LEN_SHORT/2];
-extern const int LongWindowKBD[FRAME_LEN_LONG/2];

-

-extern const unsigned char bitrevTab[17 + 129];

-extern const int cossintab[128 + 1024];

-

-#if defined (ARMV5E) && !defined (ARMV7Neon)

-extern const int twidTab64[(4*6 + 16*6)/2];

-extern const int twidTab512[(8*6 + 32*6 + 128*6)/2];

-#else

-extern const int twidTab64[4*6 + 16*6];

+extern const int LongWindowKBD[FRAME_LEN_LONG/2];
+
+extern const unsigned char bitrevTab[17 + 129];
+extern const int cossintab[128 + 1024];
+
+#if defined (ARMV5E) && !defined (ARMV7Neon)
+extern const int twidTab64[(4*6 + 16*6)/2];
+extern const int twidTab512[(8*6 + 32*6 + 128*6)/2];
+#else
+extern const int twidTab64[4*6 + 16*6];
 extern const int twidTab512[8*6 + 32*6 + 128*6];
 #endif
 
@@ -61,7 +61,7 @@
 extern const UWord8 specExpTableComb_enc[4][14];
 
 extern const Word16 quantBorders[4][4];
-//extern const Word16 quantRecon[3][4];

+//extern const Word16 quantRecon[3][4];
 extern const Word16 quantRecon[4][3];
 
 /*
@@ -92,26 +92,26 @@
 /*
   misc
 */
-extern const int sampRateTab[NUM_SAMPLE_RATES];

-extern const int BandwithCoefTab[8][NUM_SAMPLE_RATES];

-extern const int rates[8];

-extern const UWord8 sfBandTotalShort[NUM_SAMPLE_RATES];

-extern const UWord8 sfBandTotalLong[NUM_SAMPLE_RATES];

-extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES];

-extern const short sfBandTabShort[76];

-extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES];

-extern const short sfBandTabLong[325];

+extern const int sampRateTab[NUM_SAMPLE_RATES];
+extern const int BandwithCoefTab[8][NUM_SAMPLE_RATES];
+extern const int rates[8];
+extern const UWord8 sfBandTotalShort[NUM_SAMPLE_RATES];
+extern const UWord8 sfBandTotalLong[NUM_SAMPLE_RATES];
+extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES];
+extern const short sfBandTabShort[76];
+extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES];
+extern const short sfBandTabLong[325];
 
 extern const Word32 m_log2_table[INT_BITS];
 
 /*
   TNS
 */
-extern const Word32 tnsCoeff3[8];

-extern const Word32 tnsCoeff3Borders[8];

-extern const Word32 tnsCoeff4[16];

-extern const Word32 tnsCoeff4Borders[16];

-extern const Word32 invSBF[24];

-extern const Word16 sideInfoTabLong[MAX_SFB_LONG + 1];

+extern const Word32 tnsCoeff3[8];
+extern const Word32 tnsCoeff3Borders[8];
+extern const Word32 tnsCoeff4[16];
+extern const Word32 tnsCoeff4Borders[16];
+extern const Word32 invSBF[24];
+extern const Word16 sideInfoTabLong[MAX_SFB_LONG + 1];
 extern const Word16 sideInfoTabShort[MAX_SFB_SHORT + 1];
 #endif
diff --git a/media/libstagefright/codecs/aacenc/inc/aacenc_core.h b/media/libstagefright/codecs/aacenc/inc/aacenc_core.h
index faa1d20..41ba756 100644
--- a/media/libstagefright/codecs/aacenc/inc/aacenc_core.h
+++ b/media/libstagefright/codecs/aacenc/inc/aacenc_core.h
@@ -1,37 +1,37 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		aacenc_core.h

-

-	Content:	aac encoder interface functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		aacenc_core.h
+
+	Content:	aac encoder interface functions
+
 *******************************************************************************/
 
 #ifndef _aacenc_core_h_
 #define _aacenc_core_h_
 
-

+
 #include "typedef.h"
-#include "config.h"

-#include "bitenc.h"

-

-#include "psy_configuration.h"

-#include "psy_main.h"

-#include "qc_main.h"

-#include "psy_main.h"

+#include "config.h"
+#include "bitenc.h"
+
+#include "psy_configuration.h"
+#include "psy_main.h"
+#include "qc_main.h"
+#include "psy_main.h"
 /*-------------------------- defines --------------------------------------*/
 
 
@@ -41,42 +41,42 @@
   Word32   bitRate;               /* encoder bit rate in bits/sec */
   Word16   nChannelsIn;           /* number of channels on input (1,2) */
   Word16   nChannelsOut;          /* number of channels on output (1,2) */
-  Word16   bandWidth;             /* targeted audio bandwidth in Hz */

+  Word16   bandWidth;             /* targeted audio bandwidth in Hz */
   Word16   adtsUsed;			  /* whether write adts header */
 } AACENC_CONFIG;
-

-

-typedef struct {

-	

-  AACENC_CONFIG config;     /* Word16 size: 8 */

-

-  ELEMENT_INFO elInfo;      /* Word16 size: 4 */

-

-  QC_STATE qcKernel;        /* Word16 size: 6 + 5(PADDING) + 7(ELEMENT_BITS) + 54(ADJ_THR_STATE) = 72 */

-  QC_OUT   qcOut;           /* Word16 size: MAX_CHANNELS*920(QC_OUT_CHANNEL) + 5(QC_OUT_ELEMENT) + 7 = 932 / 1852 */

-

-  PSY_OUT    psyOut;        /* Word16 size: MAX_CHANNELS*186 + 2 = 188 / 374 */

-  PSY_KERNEL psyKernel;     /* Word16 size:  2587 / 4491 */

-

-  struct BITSTREAMENCODER_INIT bseInit; /* Word16 size: 6 */

-  struct BIT_BUF  bitStream;            /* Word16 size: 8 */

-  HANDLE_BIT_BUF  hBitStream;

-  int			  initOK;

-

-  short			*intbuf;

-  short			*encbuf;

-  short			*inbuf;

-  int			enclen;

-  int			inlen;

-  int			intlen;

-  int			uselength;

-

-  void			*hCheck;

-  VO_MEM_OPERATOR *voMemop;

-  VO_MEM_OPERATOR voMemoprator;

-

-}AAC_ENCODER; /* Word16 size: 3809 / 6851 */

-

+
+
+typedef struct {
+	
+  AACENC_CONFIG config;     /* Word16 size: 8 */
+
+  ELEMENT_INFO elInfo;      /* Word16 size: 4 */
+
+  QC_STATE qcKernel;        /* Word16 size: 6 + 5(PADDING) + 7(ELEMENT_BITS) + 54(ADJ_THR_STATE) = 72 */
+  QC_OUT   qcOut;           /* Word16 size: MAX_CHANNELS*920(QC_OUT_CHANNEL) + 5(QC_OUT_ELEMENT) + 7 = 932 / 1852 */
+
+  PSY_OUT    psyOut;        /* Word16 size: MAX_CHANNELS*186 + 2 = 188 / 374 */
+  PSY_KERNEL psyKernel;     /* Word16 size:  2587 / 4491 */
+
+  struct BITSTREAMENCODER_INIT bseInit; /* Word16 size: 6 */
+  struct BIT_BUF  bitStream;            /* Word16 size: 8 */
+  HANDLE_BIT_BUF  hBitStream;
+  int			  initOK;
+
+  short			*intbuf;
+  short			*encbuf;
+  short			*inbuf;
+  int			enclen;
+  int			inlen;
+  int			intlen;
+  int			uselength;
+
+  void			*hCheck;
+  VO_MEM_OPERATOR *voMemop;
+  VO_MEM_OPERATOR voMemoprator;
+
+}AAC_ENCODER; /* Word16 size: 3809 / 6851 */
+
 /*-----------------------------------------------------------------------------
 
 functionname: AacInitDefaultConfig
diff --git a/media/libstagefright/codecs/aacenc/inc/adj_thr.h b/media/libstagefright/codecs/aacenc/inc/adj_thr.h
index 4057cbe..f7cb888 100644
--- a/media/libstagefright/codecs/aacenc/inc/adj_thr.h
+++ b/media/libstagefright/codecs/aacenc/inc/adj_thr.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		adj_thr.h

-

-	Content:	Threshold compensation function 

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		adj_thr.h
+
+	Content:	Threshold compensation function 
+
 *******************************************************************************/
 
 #ifndef __ADJ_THR_H
diff --git a/media/libstagefright/codecs/aacenc/inc/adj_thr_data.h b/media/libstagefright/codecs/aacenc/inc/adj_thr_data.h
index 25dd437..9ac4664 100644
--- a/media/libstagefright/codecs/aacenc/inc/adj_thr_data.h
+++ b/media/libstagefright/codecs/aacenc/inc/adj_thr_data.h
@@ -1,29 +1,29 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		adj_thr_data.h

-

-	Content:	Threshold compensation parameter 

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		adj_thr_data.h
+
+	Content:	Threshold compensation parameter 
+
 *******************************************************************************/
 
 #ifndef __ADJ_THR_DATA_H
 #define __ADJ_THR_DATA_H
 
-#include "typedef.h"

+#include "typedef.h"
 #include "psy_const.h"
 #include "line_pe.h"
 
diff --git a/media/libstagefright/codecs/aacenc/inc/band_nrg.h b/media/libstagefright/codecs/aacenc/inc/band_nrg.h
index 68509da..65453c0 100644
--- a/media/libstagefright/codecs/aacenc/inc/band_nrg.h
+++ b/media/libstagefright/codecs/aacenc/inc/band_nrg.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		band_nrg.h

-

-	Content:	Band/Line energy calculations functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		band_nrg.h
+
+	Content:	Band/Line energy calculations functions
+
 *******************************************************************************/
 
 
diff --git a/media/libstagefright/codecs/aacenc/inc/bit_cnt.h b/media/libstagefright/codecs/aacenc/inc/bit_cnt.h
index 808319e..266a219 100644
--- a/media/libstagefright/codecs/aacenc/inc/bit_cnt.h
+++ b/media/libstagefright/codecs/aacenc/inc/bit_cnt.h
@@ -1,29 +1,29 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		bit_cnt.h

-

-	Content:	Huffman Bitcounter & coder structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		bit_cnt.h
+
+	Content:	Huffman Bitcounter & coder structure and functions
+
 *******************************************************************************/
 
 #ifndef __BITCOUNT_H
 #define __BITCOUNT_H
 
-#include "bitbuffer.h"

+#include "bitbuffer.h"
 #include "basic_op.h"
 #define INVALID_BITCOUNT (MAX_16/4)
 
diff --git a/media/libstagefright/codecs/aacenc/inc/bitbuffer.h b/media/libstagefright/codecs/aacenc/inc/bitbuffer.h
index cb850c9..e538064 100644
--- a/media/libstagefright/codecs/aacenc/inc/bitbuffer.h
+++ b/media/libstagefright/codecs/aacenc/inc/bitbuffer.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		bitbuffer.h

-

-	Content:	Bit Buffer Management structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		bitbuffer.h
+
+	Content:	Bit Buffer Management structure and functions
+
 *******************************************************************************/
 
 #ifndef BITBUFFER_H
diff --git a/media/libstagefright/codecs/aacenc/inc/bitenc.h b/media/libstagefright/codecs/aacenc/inc/bitenc.h
index 1151057..6ded3c6 100644
--- a/media/libstagefright/codecs/aacenc/inc/bitenc.h
+++ b/media/libstagefright/codecs/aacenc/inc/bitenc.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		bitenc.h

-

-	Content:	Bitstream encoder structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		bitenc.h
+
+	Content:	Bitstream encoder structure and functions
+
 *******************************************************************************/
 
 #ifndef _BITENC_H
@@ -42,8 +42,8 @@
                        ELEMENT_INFO elInfo,
                        QC_OUT *qcOut,
                        PSY_OUT *psyOut,
-                       Word16 *globUsedBits,

-                       const UWord8 *ancBytes,

+                       Word16 *globUsedBits,
+                       const UWord8 *ancBytes,
 					   Word16 samplerate
                        );
 
diff --git a/media/libstagefright/codecs/aacenc/inc/block_switch.h b/media/libstagefright/codecs/aacenc/inc/block_switch.h
index 3e35819..a4d3e8fd 100644
--- a/media/libstagefright/codecs/aacenc/inc/block_switch.h
+++ b/media/libstagefright/codecs/aacenc/inc/block_switch.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		block_switch.h

-

-	Content:	Block switching structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		block_switch.h
+
+	Content:	Block switching structure and functions
+
 *******************************************************************************/
 
 #ifndef _BLOCK_SWITCH_H
diff --git a/media/libstagefright/codecs/aacenc/inc/channel_map.h b/media/libstagefright/codecs/aacenc/inc/channel_map.h
index e3aa8dc..c361feb 100644
--- a/media/libstagefright/codecs/aacenc/inc/channel_map.h
+++ b/media/libstagefright/codecs/aacenc/inc/channel_map.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		channel_map.h

-

-	Content:	channel mapping functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		channel_map.h
+
+	Content:	channel mapping functions
+
 *******************************************************************************/
 
 #ifndef _CHANNEL_MAP_H
diff --git a/media/libstagefright/codecs/aacenc/inc/config.h b/media/libstagefright/codecs/aacenc/inc/config.h
index 6211c8f..3b29cef 100644
--- a/media/libstagefright/codecs/aacenc/inc/config.h
+++ b/media/libstagefright/codecs/aacenc/inc/config.h
@@ -1,36 +1,36 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		config.h

-

-	Content:	aac encoder parameter

-

-*******************************************************************************/

-

-#ifndef _AACENC_CONFIG_H_

-#define _AACENC_CONFIG_H_

-

-#define MAX_CHANNELS        2

-

-#define AACENC_BLOCKSIZE    1024   /*! encoder only takes BLOCKSIZE samples at a time */

-#define AACENC_TRANS_FAC    8      /*! encoder short long ratio */

-

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		config.h
+
+	Content:	aac encoder parameter
+
+*******************************************************************************/
+
+#ifndef _AACENC_CONFIG_H_
+#define _AACENC_CONFIG_H_
+
+#define MAX_CHANNELS        2
+
+#define AACENC_BLOCKSIZE    1024   /*! encoder only takes BLOCKSIZE samples at a time */
+#define AACENC_TRANS_FAC    8      /*! encoder short long ratio */
+
+
 #define MAXBITS_COEF		6144
-#define MINBITS_COEF		744

-

-

+#define MINBITS_COEF		744
+
+
 #endif
\ No newline at end of file
diff --git a/media/libstagefright/codecs/aacenc/inc/dyn_bits.h b/media/libstagefright/codecs/aacenc/inc/dyn_bits.h
index 0468fa2..d3a8a67 100644
--- a/media/libstagefright/codecs/aacenc/inc/dyn_bits.h
+++ b/media/libstagefright/codecs/aacenc/inc/dyn_bits.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		dyn_bits.h

-

-	Content:	Noiseless coder module structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		dyn_bits.h
+
+	Content:	Noiseless coder module structure and functions
+
 *******************************************************************************/
 
 #ifndef __DYN_BITS_H
diff --git a/media/libstagefright/codecs/aacenc/inc/grp_data.h b/media/libstagefright/codecs/aacenc/inc/grp_data.h
index 9666577..4c1b2cb 100644
--- a/media/libstagefright/codecs/aacenc/inc/grp_data.h
+++ b/media/libstagefright/codecs/aacenc/inc/grp_data.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		grp_data.h

-

-	Content:	Short block grouping function

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		grp_data.h
+
+	Content:	Short block grouping function
+
 *******************************************************************************/
 
 #ifndef __GRP_DATA_H__
diff --git a/media/libstagefright/codecs/aacenc/inc/interface.h b/media/libstagefright/codecs/aacenc/inc/interface.h
index b84334a..966ac99 100644
--- a/media/libstagefright/codecs/aacenc/inc/interface.h
+++ b/media/libstagefright/codecs/aacenc/inc/interface.h
@@ -1,29 +1,29 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		interface.h

-

-	Content:	psychoaccoustic/quantizer structures and interface

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		interface.h
+
+	Content:	psychoaccoustic/quantizer structures and interface
+
 *******************************************************************************/
 
 #ifndef _INTERFACE_H
 #define _INTERFACE_H
 
-#include "config.h"

+#include "config.h"
 #include "psy_const.h"
 #include "psy_data.h"
 #include "typedefs.h"
diff --git a/media/libstagefright/codecs/aacenc/inc/line_pe.h b/media/libstagefright/codecs/aacenc/inc/line_pe.h
index fed938b..038d5a3 100644
--- a/media/libstagefright/codecs/aacenc/inc/line_pe.h
+++ b/media/libstagefright/codecs/aacenc/inc/line_pe.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		line_pe.h

-

-	Content:	Perceptual entropie module structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		line_pe.h
+
+	Content:	Perceptual entropie module structure and functions
+
 *******************************************************************************/
 
 #ifndef __LINE_PE_H
diff --git a/media/libstagefright/codecs/aacenc/inc/memalign.h b/media/libstagefright/codecs/aacenc/inc/memalign.h
index 3b302a7..30bbf45 100644
--- a/media/libstagefright/codecs/aacenc/inc/memalign.h
+++ b/media/libstagefright/codecs/aacenc/inc/memalign.h
@@ -1,35 +1,35 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		memalign.h

-

-	Content:	Memory alloc alignments functions

-

-*******************************************************************************/

-

-#ifndef __VO_AACENC_MEM_ALIGN_H__

-#define __VO_AACENC_MEM_ALIGN_H__

-

-#include "voMem.h"

-#include "typedef.h"

-

-extern void *mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID);

-extern void mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID);

-

-#endif	/* __VO_MEM_ALIGN_H__ */

-

-

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		memalign.h
+
+	Content:	Memory alloc alignments functions
+
+*******************************************************************************/
+
+#ifndef __VO_AACENC_MEM_ALIGN_H__
+#define __VO_AACENC_MEM_ALIGN_H__
+
+#include "voMem.h"
+#include "typedef.h"
+
+extern void *mem_malloc(VO_MEM_OPERATOR *pMemop, unsigned int size, unsigned char alignment, unsigned int CodecID);
+extern void mem_free(VO_MEM_OPERATOR *pMemop, void *mem_ptr, unsigned int CodecID);
+
+#endif	/* __VO_MEM_ALIGN_H__ */
+
+
+
diff --git a/media/libstagefright/codecs/aacenc/inc/ms_stereo.h b/media/libstagefright/codecs/aacenc/inc/ms_stereo.h
index 6d43dec..3c03dea 100644
--- a/media/libstagefright/codecs/aacenc/inc/ms_stereo.h
+++ b/media/libstagefright/codecs/aacenc/inc/ms_stereo.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		ms_stereo.h

-

-	Content:	Declaration MS stereo processing structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		ms_stereo.h
+
+	Content:	Declaration MS stereo processing structure and functions
+
 *******************************************************************************/
 
 #ifndef __MS_STEREO_H__
diff --git a/media/libstagefright/codecs/aacenc/inc/pre_echo_control.h b/media/libstagefright/codecs/aacenc/inc/pre_echo_control.h
index 35f36e8..e719ba7 100644
--- a/media/libstagefright/codecs/aacenc/inc/pre_echo_control.h
+++ b/media/libstagefright/codecs/aacenc/inc/pre_echo_control.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		pre_echo_control.h

-

-	Content:	Pre echo control functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		pre_echo_control.h
+
+	Content:	Pre echo control functions
+
 *******************************************************************************/
 
 #ifndef __PRE_ECHO_CONTROL_H
diff --git a/media/libstagefright/codecs/aacenc/inc/psy_configuration.h b/media/libstagefright/codecs/aacenc/inc/psy_configuration.h
index 53cf25b..9abfc99 100644
--- a/media/libstagefright/codecs/aacenc/inc/psy_configuration.h
+++ b/media/libstagefright/codecs/aacenc/inc/psy_configuration.h
@@ -1,28 +1,28 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		psy_configuration.h

-

-	Content:	Psychoaccoustic configuration structure and functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		psy_configuration.h
+
+	Content:	Psychoaccoustic configuration structure and functions
+
 *******************************************************************************/
 
 #ifndef _PSY_CONFIGURATION_H
 #define _PSY_CONFIGURATION_H
-

+
 #include "typedefs.h"
 #include "psy_const.h"
 #include "tns.h"
@@ -38,7 +38,7 @@
   Word16 maxAllowedIncreaseFactor;   /* preecho control */
   Word16 minRemainingThresholdFactor;
 
-  Word16 lowpassLine;

+  Word16 lowpassLine;
   Word16 sampRateIdx;
   Word32 clipEnergy;                 /* for level dependend tmn */
 
@@ -68,7 +68,7 @@
   Word16 maxAllowedIncreaseFactor;   /* preecho control */
   Word16 minRemainingThresholdFactor;
 
-  Word16 lowpassLine;

+  Word16 lowpassLine;
   Word16 sampRateIdx;
   Word32 clipEnergy;                 /* for level dependend tmn */
 
@@ -85,10 +85,10 @@
   TNS_CONFIG tnsConf;
 
 }PSY_CONFIGURATION_SHORT; /*Word16 size: 8 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 47 = 167 */
-

-

-/* Returns the sample rate index */

-Word32 GetSRIndex(Word32 sampleRate);

+
+
+/* Returns the sample rate index */
+Word32 GetSRIndex(Word32 sampleRate);
 
 
 Word16 InitPsyConfigurationLong(Word32 bitrate,
diff --git a/media/libstagefright/codecs/aacenc/inc/psy_const.h b/media/libstagefright/codecs/aacenc/inc/psy_const.h
index 5455ab1..b05d683 100644
--- a/media/libstagefright/codecs/aacenc/inc/psy_const.h
+++ b/media/libstagefright/codecs/aacenc/inc/psy_const.h
@@ -1,37 +1,37 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		psy_const.h

-

-	Content:	Global psychoacoustic constants structures

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		psy_const.h
+
+	Content:	Global psychoacoustic constants structures
+
 *******************************************************************************/
 
 #ifndef _PSYCONST_H
 #define _PSYCONST_H
 
-#include "config.h"

+#include "config.h"
 
 #define TRUE  1
 #define FALSE 0
 
 #define FRAME_LEN_LONG    AACENC_BLOCKSIZE
 #define TRANS_FAC         8
-#define FRAME_LEN_SHORT   (FRAME_LEN_LONG/TRANS_FAC)

-

+#define FRAME_LEN_SHORT   (FRAME_LEN_LONG/TRANS_FAC)
+
 
 
 /* Block types */
@@ -74,7 +74,7 @@
 #define TRANSFORM_OFFSET_SHORT   448
 
 #define LOG_NORM_PCM          -15
-

+
 #define NUM_SAMPLE_RATES	12
 
 #endif /* _PSYCONST_H */
diff --git a/media/libstagefright/codecs/aacenc/inc/psy_data.h b/media/libstagefright/codecs/aacenc/inc/psy_data.h
index 1412d53..3ea6a84 100644
--- a/media/libstagefright/codecs/aacenc/inc/psy_data.h
+++ b/media/libstagefright/codecs/aacenc/inc/psy_data.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		psy_data.h

-

-	Content:	Psychoacoustic data and structures

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		psy_data.h
+
+	Content:	Psychoacoustic data and structures
+
 *******************************************************************************/
 
 #ifndef _PSY_DATA_H
diff --git a/media/libstagefright/codecs/aacenc/inc/psy_main.h b/media/libstagefright/codecs/aacenc/inc/psy_main.h
index ab0b8b1..5fcbe13 100644
--- a/media/libstagefright/codecs/aacenc/inc/psy_main.h
+++ b/media/libstagefright/codecs/aacenc/inc/psy_main.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		psy_main.h

-

-	Content:	Psychoacoustic major function block

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		psy_main.h
+
+	Content:	Psychoacoustic major function block
+
 *******************************************************************************/
 
 #ifndef _PSYMAIN_H
@@ -35,7 +35,7 @@
   PSY_CONFIGURATION_SHORT psyConfShort;          /* Word16 size: 167 */
   PSY_DATA                psyData[MAX_CHANNELS]; /* Word16 size: MAX_CHANNELS*1669*/
   TNS_DATA                tnsData[MAX_CHANNELS]; /* Word16 size: MAX_CHANNELS*235 */
-  Word32*                 pScratchTns;

+  Word32*                 pScratchTns;
   Word16				  sampleRateIdx;
 }PSY_KERNEL; /* Word16 size: 2587 / 4491 */
 
diff --git a/media/libstagefright/codecs/aacenc/inc/qc_data.h b/media/libstagefright/codecs/aacenc/inc/qc_data.h
index 81d4051..109922df 100644
--- a/media/libstagefright/codecs/aacenc/inc/qc_data.h
+++ b/media/libstagefright/codecs/aacenc/inc/qc_data.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		qc_data.h

-

-	Content:	Quantizing & coding structures

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		qc_data.h
+
+	Content:	Quantizing & coding structures
+
 *******************************************************************************/
 
 #ifndef _QC_DATA_H
@@ -89,7 +89,7 @@
 
 typedef struct
 {
-  Word16		  adtsUsed;

+  Word16		  adtsUsed;
   Word16          staticBitsUsed; /* for verification purposes */
   Word16          dynBitsUsed;    /* for verification purposes */
   Word16          pe;
diff --git a/media/libstagefright/codecs/aacenc/inc/qc_main.h b/media/libstagefright/codecs/aacenc/inc/qc_main.h
index e1138b2..924a06d 100644
--- a/media/libstagefright/codecs/aacenc/inc/qc_main.h
+++ b/media/libstagefright/codecs/aacenc/inc/qc_main.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		qc_main.h

-

-	Content:	Quantizing & coding functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		qc_main.h
+
+	Content:	Quantizing & coding functions
+
 *******************************************************************************/
 
 #ifndef _QC_MAIN_H
diff --git a/media/libstagefright/codecs/aacenc/inc/quantize.h b/media/libstagefright/codecs/aacenc/inc/quantize.h
index 88a95e1..7dac2bf 100644
--- a/media/libstagefright/codecs/aacenc/inc/quantize.h
+++ b/media/libstagefright/codecs/aacenc/inc/quantize.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		quantize.h

-

-	Content:	Quantization functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		quantize.h
+
+	Content:	Quantization functions
+
 *******************************************************************************/
 
 #ifndef _QUANTIZE_H_
diff --git a/media/libstagefright/codecs/aacenc/inc/sf_estim.h b/media/libstagefright/codecs/aacenc/inc/sf_estim.h
index b25ec3c..11436a2 100644
--- a/media/libstagefright/codecs/aacenc/inc/sf_estim.h
+++ b/media/libstagefright/codecs/aacenc/inc/sf_estim.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		sf_estim.h

-

-	Content:	Scale factor estimation functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		sf_estim.h
+
+	Content:	Scale factor estimation functions
+
 *******************************************************************************/
 
 #ifndef __SF_ESTIM_H__
diff --git a/media/libstagefright/codecs/aacenc/inc/spreading.h b/media/libstagefright/codecs/aacenc/inc/spreading.h
index 29cf63d..0c96fc7 100644
--- a/media/libstagefright/codecs/aacenc/inc/spreading.h
+++ b/media/libstagefright/codecs/aacenc/inc/spreading.h
@@ -1,29 +1,29 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		spreading.h

-

-	Content:	Spreading of energy functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		spreading.h
+
+	Content:	Spreading of energy functions
+
 *******************************************************************************/
 
 #ifndef _SPREADING_H
 #define _SPREADING_H
 #include "typedefs.h"
-

+
 
 void SpreadingMax(const Word16 pbCnt,
                   const Word16 *maskLowFactor,
diff --git a/media/libstagefright/codecs/aacenc/inc/stat_bits.h b/media/libstagefright/codecs/aacenc/inc/stat_bits.h
index 6e90b9c..fff3d14 100644
--- a/media/libstagefright/codecs/aacenc/inc/stat_bits.h
+++ b/media/libstagefright/codecs/aacenc/inc/stat_bits.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		stat_bits.h

-

-	Content:	Static bit counter functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		stat_bits.h
+
+	Content:	Static bit counter functions
+
 *******************************************************************************/
 
 #ifndef __STAT_BITS_H
@@ -28,7 +28,7 @@
 
 Word16 countStaticBitdemand(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
                             PSY_OUT_ELEMENT *psyOutElement,
-                            Word16 nChannels, 

+                            Word16 nChannels, 
 							Word16 adtsUsed);
 
 #endif /* __STAT_BITS_H */
diff --git a/media/libstagefright/codecs/aacenc/inc/tns.h b/media/libstagefright/codecs/aacenc/inc/tns.h
index 9ffcce9..40cfaee 100644
--- a/media/libstagefright/codecs/aacenc/inc/tns.h
+++ b/media/libstagefright/codecs/aacenc/inc/tns.h
@@ -1,28 +1,28 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		tns.h

-

-	Content:	TNS structures

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		tns.h
+
+	Content:	TNS structures
+
 *******************************************************************************/
 
 #ifndef _TNS_H
 #define _TNS_H
-

+
 #include "typedef.h"
 #include "psy_const.h"
 
diff --git a/media/libstagefright/codecs/aacenc/inc/tns_func.h b/media/libstagefright/codecs/aacenc/inc/tns_func.h
index 58b75b6..02df24d 100644
--- a/media/libstagefright/codecs/aacenc/inc/tns_func.h
+++ b/media/libstagefright/codecs/aacenc/inc/tns_func.h
@@ -1,30 +1,30 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		tns_func.h

-

-	Content:	TNS functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		tns_func.h
+
+	Content:	TNS functions
+
 *******************************************************************************/
 
 /*
    Temporal noise shaping
  */
 #ifndef _TNS_FUNC_H
-#define _TNS_FUNC_H

+#define _TNS_FUNC_H
 #include "typedef.h"
 #include "psy_configuration.h"
 
diff --git a/media/libstagefright/codecs/aacenc/inc/tns_param.h b/media/libstagefright/codecs/aacenc/inc/tns_param.h
index 26266ac..78265bb 100644
--- a/media/libstagefright/codecs/aacenc/inc/tns_param.h
+++ b/media/libstagefright/codecs/aacenc/inc/tns_param.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		tns_param.h

-

-	Content:	TNS parameters

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		tns_param.h
+
+	Content:	TNS parameters
+
 *******************************************************************************/
 
 /*
diff --git a/media/libstagefright/codecs/aacenc/inc/transform.h b/media/libstagefright/codecs/aacenc/inc/transform.h
index 2666914..93d5ffe 100644
--- a/media/libstagefright/codecs/aacenc/inc/transform.h
+++ b/media/libstagefright/codecs/aacenc/inc/transform.h
@@ -1,23 +1,23 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		transform.h

-

-	Content:	MDCT Transform functions

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		transform.h
+
+	Content:	MDCT Transform functions
+
 *******************************************************************************/
 
 #ifndef  __TRANSFORM_H__
diff --git a/media/libstagefright/codecs/aacenc/src/aac_rom.c b/media/libstagefright/codecs/aacenc/src/aac_rom.c
index 2ce0352..16b44e0 100644
--- a/media/libstagefright/codecs/aacenc/src/aac_rom.c
+++ b/media/libstagefright/codecs/aacenc/src/aac_rom.c
@@ -1,358 +1,358 @@
-/*

- ** Copyright 2003-2010, VisualOn, Inc.

- **

- ** Licensed under the Apache License, Version 2.0 (the "License");

- ** you may not use this file except in compliance with the License.

- ** You may obtain a copy of the License at

- **

- **     http://www.apache.org/licenses/LICENSE-2.0

- **

- ** Unless required by applicable law or agreed to in writing, software

- ** distributed under the License is distributed on an "AS IS" BASIS,

- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- ** See the License for the specific language governing permissions and

- ** limitations under the License.

- */

-/*******************************************************************************

-	File:		aac_rom.c

-

-	Content:	constant tables

-

+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** Licensed under the Apache License, Version 2.0 (the "License");
+ ** you may not use this file except in compliance with the License.
+ ** You may obtain a copy of the License at
+ **
+ **     http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing, software
+ ** distributed under the License is distributed on an "AS IS" BASIS,
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ** See the License for the specific language governing permissions and
+ ** limitations under the License.
+ */
+/*******************************************************************************
+	File:		aac_rom.c
+
+	Content:	constant tables
+
 *******************************************************************************/
 
-#include "aac_rom.h"

-

-#if defined (ARMV5E) && !defined (ARMV7Neon)

-

-/* 

- *  Q30 for 128 and 1024 

- *

- * for (i = 0; i < num/4; i++) {

- *   angle = (i + 0.125) * M_PI / num;

- *   x = cos(angle) * (1 << 30);

- *   x = sin(angle) * (1 << 30);

- * 

- *   angle = (num/2 - 1 - i + 0.125) * M_PI / num;

- *   x = cos(angle) * (1 << 30);

- *   x = sin(angle) * (1 << 30);

- * }

- */

-const int cossintab[128 + 1024] = {

-	/* 128 */

-	0x3fffec43, 0x003243f1, 0x015fd4d2, 0x3ffc38d1, 0x3ff9c13a, 0x01c454f5, 0x02f1b755, 0x3feea776, 

-	0x3fe9b8a9, 0x03562038, 0x0483259d, 0x3fd73a4a, 0x3fcfd50b, 0x04e767c5, 0x0613e1c5, 0x3fb5f4ea, 

-	0x3fac1a5b, 0x0677edbb, 0x07a3adff, 0x3f8adc77, 0x3f7e8e1e, 0x08077457, 0x09324ca7, 0x3f55f796, 

-	0x3f473759, 0x0995bdfd, 0x0abf8043, 0x3f174e70, 0x3f061e95, 0x0b228d42, 0x0c4b0b94, 0x3eceeaad, 

-	0x3ebb4ddb, 0x0cada4f5, 0x0dd4b19a, 0x3e7cd778, 0x3e66d0b4, 0x0e36c82a, 0x0f5c35a3, 0x3e212179, 

-	0x3e08b42a, 0x0fbdba40, 0x10e15b4e, 0x3dbbd6d4, 0x3da106bd, 0x11423ef0, 0x1263e699, 0x3d4d0728, 

-	0x3d2fd86c, 0x12c41a4f, 0x13e39be9, 0x3cd4c38b, 0x3cb53aaa, 0x144310dd, 0x15604013, 0x3c531e88, 

-	0x3c314060, 0x15bee78c, 0x16d99864, 0x3bc82c1f, 0x3ba3fde7, 0x173763c9, 0x184f6aab, 0x3b3401bb, 

-	0x3b0d8909, 0x18ac4b87, 0x19c17d44, 0x3a96b636, 0x3a6df8f8, 0x1a1d6544, 0x1b2f971e, 0x39f061d2, 

-	0x39c5664f, 0x1b8a7815, 0x1c997fc4, 0x39411e33, 0x3913eb0e, 0x1cf34baf, 0x1dfeff67, 0x38890663, 

-	0x3859a292, 0x1e57a86d, 0x1f5fdee6, 0x37c836c2, 0x3796a996, 0x1fb7575c, 0x20bbe7d8, 0x36fecd0e, 

-	0x36cb1e2a, 0x21122240, 0x2212e492, 0x362ce855, 0x35f71fb1, 0x2267d3a0, 0x2364a02e, 0x3552a8f4, 

-	0x351acedd, 0x23b836ca, 0x24b0e699, 0x34703095, 0x34364da6, 0x250317df, 0x25f78497, 0x3385a222, 

-	0x3349bf48, 0x264843d9, 0x273847c8, 0x329321c7, 0x32554840, 0x27878893, 0x2872feb6, 0x3198d4ea, 

-	0x31590e3e, 0x28c0b4d2, 0x29a778db, 0x3096e223, 0x30553828, 0x29f3984c, 0x2ad586a3, 0x2f8d713a, 

-	0x2f49ee0f, 0x2b2003ac, 0x2bfcf97c, 0x2e7cab1c, 0x2e37592c, 0x2c45c8a0, 0x2d1da3d5, 0x2d64b9da, 

-	/* 1024 */

-	0x3fffffb1, 0x0006487f, 0x002bfb74, 0x3ffff0e3, 0x3fffe705, 0x00388c6e, 0x005e3f4c, 0x3fffba9b, 

-	0x3fffa6de, 0x006ad03b, 0x009082ea, 0x3fff5cd8, 0x3fff3f3c, 0x009d13c5, 0x00c2c62f, 0x3ffed79b, 

-	0x3ffeb021, 0x00cf56ef, 0x00f508fc, 0x3ffe2ae5, 0x3ffdf98c, 0x01019998, 0x01274b31, 0x3ffd56b5, 

-	0x3ffd1b7e, 0x0133dba3, 0x01598cb1, 0x3ffc5b0c, 0x3ffc15f7, 0x01661cf0, 0x018bcd5b, 0x3ffb37ec, 

-	0x3ffae8f9, 0x01985d60, 0x01be0d11, 0x3ff9ed53, 0x3ff99483, 0x01ca9cd4, 0x01f04bb4, 0x3ff87b44, 

-	0x3ff81896, 0x01fcdb2e, 0x02228924, 0x3ff6e1bf, 0x3ff67534, 0x022f184d, 0x0254c544, 0x3ff520c5, 

-	0x3ff4aa5d, 0x02615414, 0x0286fff3, 0x3ff33858, 0x3ff2b813, 0x02938e62, 0x02b93914, 0x3ff12878, 

-	0x3ff09e56, 0x02c5c71a, 0x02eb7086, 0x3feef126, 0x3fee5d28, 0x02f7fe1c, 0x031da62b, 0x3fec9265, 

-	0x3febf48b, 0x032a3349, 0x034fd9e5, 0x3fea0c35, 0x3fe96480, 0x035c6682, 0x03820b93, 0x3fe75e98, 

-	0x3fe6ad08, 0x038e97a9, 0x03b43b17, 0x3fe48990, 0x3fe3ce26, 0x03c0c69e, 0x03e66852, 0x3fe18d1f, 

-	0x3fe0c7da, 0x03f2f342, 0x04189326, 0x3fde6945, 0x3fdd9a27, 0x04251d77, 0x044abb73, 0x3fdb1e06, 

-	0x3fda450f, 0x0457451d, 0x047ce11a, 0x3fd7ab64, 0x3fd6c894, 0x04896a16, 0x04af03fc, 0x3fd4115f, 

-	0x3fd324b7, 0x04bb8c42, 0x04e123fa, 0x3fd04ffc, 0x3fcf597c, 0x04edab83, 0x051340f6, 0x3fcc673b, 

-	0x3fcb66e4, 0x051fc7b9, 0x05455ad1, 0x3fc8571f, 0x3fc74cf3, 0x0551e0c7, 0x0577716b, 0x3fc41fac, 

-	0x3fc30baa, 0x0583f68c, 0x05a984a6, 0x3fbfc0e3, 0x3fbea30c, 0x05b608eb, 0x05db9463, 0x3fbb3ac7, 

-	0x3fba131b, 0x05e817c3, 0x060da083, 0x3fb68d5b, 0x3fb55bdc, 0x061a22f7, 0x063fa8e7, 0x3fb1b8a2, 

-	0x3fb07d50, 0x064c2a67, 0x0671ad71, 0x3facbc9f, 0x3fab777b, 0x067e2df5, 0x06a3ae00, 0x3fa79954, 

-	0x3fa64a5f, 0x06b02d81, 0x06d5aa77, 0x3fa24ec6, 0x3fa0f600, 0x06e228ee, 0x0707a2b7, 0x3f9cdcf7, 

-	0x3f9b7a62, 0x0714201b, 0x073996a1, 0x3f9743eb, 0x3f95d787, 0x074612eb, 0x076b8616, 0x3f9183a5, 

-	0x3f900d72, 0x0778013d, 0x079d70f7, 0x3f8b9c28, 0x3f8a1c29, 0x07a9eaf5, 0x07cf5726, 0x3f858d79, 

-	0x3f8403ae, 0x07dbcff2, 0x08013883, 0x3f7f579b, 0x3f7dc405, 0x080db016, 0x083314f1, 0x3f78fa92, 

-	0x3f775d31, 0x083f8b43, 0x0864ec4f, 0x3f727661, 0x3f70cf38, 0x08716159, 0x0896be80, 0x3f6bcb0e, 

-	0x3f6a1a1c, 0x08a3323a, 0x08c88b65, 0x3f64f89b, 0x3f633de2, 0x08d4fdc6, 0x08fa52de, 0x3f5dff0e, 

-	0x3f5c3a8f, 0x0906c3e0, 0x092c14ce, 0x3f56de6a, 0x3f551026, 0x09388469, 0x095dd116, 0x3f4f96b4, 

-	0x3f4dbeac, 0x096a3f42, 0x098f8796, 0x3f4827f0, 0x3f464626, 0x099bf44c, 0x09c13831, 0x3f409223, 

-	0x3f3ea697, 0x09cda368, 0x09f2e2c7, 0x3f38d552, 0x3f36e006, 0x09ff4c78, 0x0a24873a, 0x3f30f181, 

-	0x3f2ef276, 0x0a30ef5e, 0x0a56256c, 0x3f28e6b6, 0x3f26ddec, 0x0a628bfa, 0x0a87bd3d, 0x3f20b4f5, 

-	0x3f1ea26e, 0x0a94222f, 0x0ab94e8f, 0x3f185c43, 0x3f164001, 0x0ac5b1dc, 0x0aead944, 0x3f0fdca5, 

-	0x3f0db6a9, 0x0af73ae5, 0x0b1c5d3d, 0x3f073621, 0x3f05066d, 0x0b28bd2a, 0x0b4dda5c, 0x3efe68bc, 

-	0x3efc2f50, 0x0b5a388d, 0x0b7f5081, 0x3ef5747b, 0x3ef3315a, 0x0b8bacf0, 0x0bb0bf8f, 0x3eec5965, 

-	0x3eea0c8e, 0x0bbd1a33, 0x0be22766, 0x3ee3177e, 0x3ee0c0f4, 0x0bee8038, 0x0c1387e9, 0x3ed9aecc, 

-	0x3ed74e91, 0x0c1fdee1, 0x0c44e0f9, 0x3ed01f55, 0x3ecdb56a, 0x0c513610, 0x0c763278, 0x3ec66920, 

-	0x3ec3f585, 0x0c8285a5, 0x0ca77c47, 0x3ebc8c31, 0x3eba0ee9, 0x0cb3cd84, 0x0cd8be47, 0x3eb2888f, 

-	0x3eb0019c, 0x0ce50d8c, 0x0d09f85b, 0x3ea85e41, 0x3ea5cda3, 0x0d1645a0, 0x0d3b2a64, 0x3e9e0d4c, 

-	0x3e9b7306, 0x0d4775a1, 0x0d6c5443, 0x3e9395b7, 0x3e90f1ca, 0x0d789d71, 0x0d9d75db, 0x3e88f788, 

-	0x3e8649f5, 0x0da9bcf2, 0x0dce8f0d, 0x3e7e32c6, 0x3e7b7b90, 0x0ddad406, 0x0dff9fba, 0x3e734778, 

-	0x3e70869f, 0x0e0be28e, 0x0e30a7c5, 0x3e6835a4, 0x3e656b2b, 0x0e3ce86b, 0x0e61a70f, 0x3e5cfd51, 

-	0x3e5a2939, 0x0e6de580, 0x0e929d7a, 0x3e519e86, 0x3e4ec0d1, 0x0e9ed9af, 0x0ec38ae8, 0x3e46194a, 

-	0x3e4331fa, 0x0ecfc4d9, 0x0ef46f3b, 0x3e3a6da4, 0x3e377cbb, 0x0f00a6df, 0x0f254a53, 0x3e2e9b9c, 

-	0x3e2ba11b, 0x0f317fa5, 0x0f561c15, 0x3e22a338, 0x3e1f9f21, 0x0f624f0c, 0x0f86e460, 0x3e168480, 

-	0x3e1376d5, 0x0f9314f5, 0x0fb7a317, 0x3e0a3f7b, 0x3e07283f, 0x0fc3d143, 0x0fe8581d, 0x3dfdd432, 

-	0x3dfab365, 0x0ff483d7, 0x10190352, 0x3df142ab, 0x3dee1851, 0x10252c94, 0x1049a49a, 0x3de48aef, 

-	0x3de15708, 0x1055cb5b, 0x107a3bd5, 0x3dd7ad05, 0x3dd46f94, 0x1086600e, 0x10aac8e6, 0x3dcaa8f5, 

-	0x3dc761fc, 0x10b6ea90, 0x10db4baf, 0x3dbd7ec7, 0x3dba2e48, 0x10e76ac3, 0x110bc413, 0x3db02e84, 

-	0x3dacd481, 0x1117e088, 0x113c31f3, 0x3da2b834, 0x3d9f54af, 0x11484bc2, 0x116c9531, 0x3d951bde, 

-	0x3d91aed9, 0x1178ac53, 0x119cedaf, 0x3d87598c, 0x3d83e309, 0x11a9021d, 0x11cd3b50, 0x3d797145, 

-	0x3d75f147, 0x11d94d02, 0x11fd7df6, 0x3d6b6313, 0x3d67d99b, 0x12098ce5, 0x122db583, 0x3d5d2efe, 

-	0x3d599c0e, 0x1239c1a7, 0x125de1da, 0x3d4ed50f, 0x3d4b38aa, 0x1269eb2b, 0x128e02dc, 0x3d40554e, 

-	0x3d3caf76, 0x129a0954, 0x12be186c, 0x3d31afc5, 0x3d2e007c, 0x12ca1c03, 0x12ee226c, 0x3d22e47c, 

-	0x3d1f2bc5, 0x12fa231b, 0x131e20c0, 0x3d13f37e, 0x3d10315a, 0x132a1e7e, 0x134e1348, 0x3d04dcd2, 

-	0x3d011145, 0x135a0e0e, 0x137df9e7, 0x3cf5a082, 0x3cf1cb8e, 0x1389f1af, 0x13add481, 0x3ce63e98, 

-	0x3ce2603f, 0x13b9c943, 0x13dda2f7, 0x3cd6b71e, 0x3cd2cf62, 0x13e994ab, 0x140d652c, 0x3cc70a1c, 

-	0x3cc318ff, 0x141953cb, 0x143d1b02, 0x3cb7379c, 0x3cb33d22, 0x14490685, 0x146cc45c, 0x3ca73fa9, 

-	0x3ca33bd3, 0x1478acbc, 0x149c611d, 0x3c97224c, 0x3c93151d, 0x14a84652, 0x14cbf127, 0x3c86df8e, 

-	0x3c82c909, 0x14d7d32a, 0x14fb745e, 0x3c76777b, 0x3c7257a2, 0x15075327, 0x152aeaa3, 0x3c65ea1c, 

-	0x3c61c0f1, 0x1536c62b, 0x155a53d9, 0x3c55377b, 0x3c510501, 0x15662c18, 0x1589afe3, 0x3c445fa2, 

-	0x3c4023dd, 0x159584d3, 0x15b8fea4, 0x3c33629d, 0x3c2f1d8e, 0x15c4d03e, 0x15e83fff, 0x3c224075, 

-	0x3c1df21f, 0x15f40e3a, 0x161773d6, 0x3c10f935, 0x3c0ca19b, 0x16233eac, 0x16469a0d, 0x3bff8ce8, 

-	0x3bfb2c0c, 0x16526176, 0x1675b286, 0x3bedfb99, 0x3be9917e, 0x1681767c, 0x16a4bd25, 0x3bdc4552, 

-	0x3bd7d1fa, 0x16b07d9f, 0x16d3b9cc, 0x3bca6a1d, 0x3bc5ed8d, 0x16df76c3, 0x1702a85e, 0x3bb86a08, 

-	0x3bb3e440, 0x170e61cc, 0x173188be, 0x3ba6451b, 0x3ba1b620, 0x173d3e9b, 0x17605ad0, 0x3b93fb63, 

-	0x3b8f6337, 0x176c0d15, 0x178f1e76, 0x3b818ceb, 0x3b7ceb90, 0x179acd1c, 0x17bdd394, 0x3b6ef9be, 

-	0x3b6a4f38, 0x17c97e93, 0x17ec7a0d, 0x3b5c41e8, 0x3b578e39, 0x17f8215e, 0x181b11c4, 0x3b496574, 

-	0x3b44a8a0, 0x1826b561, 0x18499a9d, 0x3b36646e, 0x3b319e77, 0x18553a7d, 0x1878147a, 0x3b233ee1, 

-	0x3b1e6fca, 0x1883b097, 0x18a67f3f, 0x3b0ff4d9, 0x3b0b1ca6, 0x18b21791, 0x18d4dad0, 0x3afc8663, 

-	0x3af7a516, 0x18e06f50, 0x1903270f, 0x3ae8f38b, 0x3ae40926, 0x190eb7b7, 0x193163e1, 0x3ad53c5b, 

-	0x3ad048e3, 0x193cf0a9, 0x195f9128, 0x3ac160e1, 0x3abc6458, 0x196b1a09, 0x198daec8, 0x3aad6129, 

-	0x3aa85b92, 0x199933bb, 0x19bbbca6, 0x3a993d3e, 0x3a942e9d, 0x19c73da3, 0x19e9baa3, 0x3a84f52f, 

-	0x3a7fdd86, 0x19f537a4, 0x1a17a8a5, 0x3a708906, 0x3a6b6859, 0x1a2321a2, 0x1a45868e, 0x3a5bf8d1, 

-	0x3a56cf23, 0x1a50fb81, 0x1a735442, 0x3a47449c, 0x3a4211f0, 0x1a7ec524, 0x1aa111a6, 0x3a326c74, 

-	0x3a2d30cd, 0x1aac7e6f, 0x1acebe9d, 0x3a1d7066, 0x3a182bc8, 0x1ada2746, 0x1afc5b0a, 0x3a08507f, 

-	0x3a0302ed, 0x1b07bf8c, 0x1b29e6d2, 0x39f30ccc, 0x39edb649, 0x1b354727, 0x1b5761d8, 0x39dda55a, 

-	0x39d845e9, 0x1b62bdf8, 0x1b84cc01, 0x39c81a36, 0x39c2b1da, 0x1b9023e5, 0x1bb22530, 0x39b26b6d, 

-	0x39acfa2b, 0x1bbd78d2, 0x1bdf6d4a, 0x399c990d, 0x39971ee7, 0x1beabca1, 0x1c0ca432, 0x3986a324, 

-	0x3981201e, 0x1c17ef39, 0x1c39c9cd, 0x397089bf, 0x396afddc, 0x1c45107c, 0x1c66ddfe, 0x395a4ceb, 

-	0x3954b82e, 0x1c72204f, 0x1c93e0ab, 0x3943ecb6, 0x393e4f23, 0x1c9f1e96, 0x1cc0d1b6, 0x392d692f, 

-	0x3927c2c9, 0x1ccc0b35, 0x1cedb106, 0x3916c262, 0x3911132d, 0x1cf8e611, 0x1d1a7e7d, 0x38fff85e, 

-	0x38fa405e, 0x1d25af0d, 0x1d473a00, 0x38e90b31, 0x38e34a69, 0x1d52660f, 0x1d73e374, 0x38d1fae9, 

-	0x38cc315d, 0x1d7f0afb, 0x1da07abc, 0x38bac795, 0x38b4f547, 0x1dab9db5, 0x1dccffbf, 0x38a37142, 

-	0x389d9637, 0x1dd81e21, 0x1df9725f, 0x388bf7ff, 0x3886143b, 0x1e048c24, 0x1e25d282, 0x38745bdb, 

-	0x386e6f60, 0x1e30e7a4, 0x1e52200c, 0x385c9ce3, 0x3856a7b6, 0x1e5d3084, 0x1e7e5ae2, 0x3844bb28, 

-	0x383ebd4c, 0x1e8966a8, 0x1eaa82e9, 0x382cb6b7, 0x3826b030, 0x1eb589f7, 0x1ed69805, 0x38148f9f, 

-	0x380e8071, 0x1ee19a54, 0x1f029a1c, 0x37fc45ef, 0x37f62e1d, 0x1f0d97a5, 0x1f2e8911, 0x37e3d9b7, 

-	0x37ddb945, 0x1f3981ce, 0x1f5a64cb, 0x37cb4b04, 0x37c521f6, 0x1f6558b5, 0x1f862d2d, 0x37b299e7, 

-	0x37ac6841, 0x1f911c3d, 0x1fb1e21d, 0x3799c66f, 0x37938c34, 0x1fbccc4d, 0x1fdd8381, 0x3780d0aa, 

-	0x377a8ddf, 0x1fe868c8, 0x2009113c, 0x3767b8a9, 0x37616d51, 0x2013f196, 0x20348b35, 0x374e7e7b, 

-	0x37482a9a, 0x203f6699, 0x205ff14f, 0x3735222f, 0x372ec5c9, 0x206ac7b8, 0x208b4372, 0x371ba3d4, 

-	0x37153eee, 0x209614d9, 0x20b68181, 0x3702037c, 0x36fb9618, 0x20c14ddf, 0x20e1ab63, 0x36e84135, 

-	0x36e1cb58, 0x20ec72b1, 0x210cc0fc, 0x36ce5d10, 0x36c7debd, 0x21178334, 0x2137c232, 0x36b4571b, 

-	0x36add058, 0x21427f4d, 0x2162aeea, 0x369a2f69, 0x3693a038, 0x216d66e2, 0x218d870b, 0x367fe608, 

-	0x36794e6e, 0x219839d8, 0x21b84a79, 0x36657b08, 0x365edb09, 0x21c2f815, 0x21e2f91a, 0x364aee7b, 

-	0x3644461b, 0x21eda17f, 0x220d92d4, 0x36304070, 0x36298fb4, 0x221835fb, 0x2238178d, 0x361570f8, 

-	0x360eb7e3, 0x2242b56f, 0x22628729, 0x35fa8023, 0x35f3beba, 0x226d1fc1, 0x228ce191, 0x35df6e03, 

-	0x35d8a449, 0x229774d7, 0x22b726a8, 0x35c43aa7, 0x35bd68a1, 0x22c1b496, 0x22e15655, 0x35a8e621, 

-	0x35a20bd3, 0x22ebdee5, 0x230b707e, 0x358d7081, 0x35868def, 0x2315f3a8, 0x23357509, 0x3571d9d9, 

-	0x356aef08, 0x233ff2c8, 0x235f63dc, 0x35562239, 0x354f2f2c, 0x2369dc29, 0x23893cdd, 0x353a49b2, 

-	0x35334e6f, 0x2393afb2, 0x23b2fff3, 0x351e5056, 0x35174ce0, 0x23bd6d48, 0x23dcad03, 0x35023636, 

-	0x34fb2a92, 0x23e714d3, 0x240643f4, 0x34e5fb63, 0x34dee795, 0x2410a639, 0x242fc4ad, 0x34c99fef, 

-	0x34c283fb, 0x243a215f, 0x24592f13, 0x34ad23eb, 0x34a5ffd5, 0x2463862c, 0x2482830d, 0x34908768, 

-	0x34895b36, 0x248cd487, 0x24abc082, 0x3473ca79, 0x346c962f, 0x24b60c57, 0x24d4e757, 0x3456ed2f, 

-	0x344fb0d1, 0x24df2d81, 0x24fdf775, 0x3439ef9c, 0x3432ab2e, 0x250837ed, 0x2526f0c1, 0x341cd1d2, 

-	0x34158559, 0x25312b81, 0x254fd323, 0x33ff93e2, 0x33f83f62, 0x255a0823, 0x25789e80, 0x33e235df, 

-	0x33dad95e, 0x2582cdbc, 0x25a152c0, 0x33c4b7db, 0x33bd535c, 0x25ab7c30, 0x25c9efca, 0x33a719e8, 

-	0x339fad70, 0x25d41369, 0x25f27584, 0x33895c18, 0x3381e7ac, 0x25fc934b, 0x261ae3d6, 0x336b7e7e, 

-	0x33640223, 0x2624fbbf, 0x26433aa7, 0x334d812d, 0x3345fce6, 0x264d4cac, 0x266b79dd, 0x332f6435, 

-	0x3327d808, 0x267585f8, 0x2693a161, 0x331127ab, 0x3309939c, 0x269da78b, 0x26bbb119, 0x32f2cba1, 

-	0x32eb2fb5, 0x26c5b14c, 0x26e3a8ec, 0x32d45029, 0x32ccac64, 0x26eda322, 0x270b88c2, 0x32b5b557, 

-	0x32ae09be, 0x27157cf5, 0x27335082, 0x3296fb3d, 0x328f47d5, 0x273d3eac, 0x275b0014, 0x327821ee, 

-	0x327066bc, 0x2764e82f, 0x27829760, 0x3259297d, 0x32516686, 0x278c7965, 0x27aa164c, 0x323a11fe, 

-	0x32324746, 0x27b3f235, 0x27d17cc1, 0x321adb83, 0x3213090f, 0x27db5288, 0x27f8caa5, 0x31fb8620, 

-	0x31f3abf5, 0x28029a45, 0x281fffe2, 0x31dc11e8, 0x31d4300b, 0x2829c954, 0x28471c5e, 0x31bc7eee, 

-	0x31b49564, 0x2850df9d, 0x286e2002, 0x319ccd46, 0x3194dc14, 0x2877dd07, 0x28950ab6, 0x317cfd04, 

-	0x3175042e, 0x289ec17a, 0x28bbdc61, 0x315d0e3b, 0x31550dc6, 0x28c58cdf, 0x28e294eb, 0x313d00ff, 

-	0x3134f8f1, 0x28ec3f1e, 0x2909343e, 0x311cd564, 0x3114c5c0, 0x2912d81f, 0x292fba40, 0x30fc8b7d, 

-	0x30f47449, 0x293957c9, 0x295626da, 0x30dc235e, 0x30d404a0, 0x295fbe06, 0x297c79f5, 0x30bb9d1c, 

-	0x30b376d8, 0x29860abd, 0x29a2b378, 0x309af8ca, 0x3092cb05, 0x29ac3dd7, 0x29c8d34d, 0x307a367c, 

-	0x3072013c, 0x29d2573c, 0x29eed95b, 0x30595648, 0x30511991, 0x29f856d5, 0x2a14c58b, 0x30385840, 

-	0x30301418, 0x2a1e3c8a, 0x2a3a97c7, 0x30173c7a, 0x300ef0e5, 0x2a440844, 0x2a604ff5, 0x2ff6030a, 

-	0x2fedb00d, 0x2a69b9ec, 0x2a85ee00, 0x2fd4ac04, 0x2fcc51a5, 0x2a8f516b, 0x2aab71d0, 0x2fb3377c, 

-	0x2faad5c1, 0x2ab4cea9, 0x2ad0db4e, 0x2f91a589, 0x2f893c75, 0x2ada318e, 0x2af62a63, 0x2f6ff63d, 

-	0x2f6785d7, 0x2aff7a05, 0x2b1b5ef8, 0x2f4e29af, 0x2f45b1fb, 0x2b24a7f6, 0x2b4078f5, 0x2f2c3ff2, 

-	0x2f23c0f6, 0x2b49bb4a, 0x2b657844, 0x2f0a391d, 0x2f01b2de, 0x2b6eb3ea, 0x2b8a5cce, 0x2ee81543, 

-	0x2edf87c6, 0x2b9391c0, 0x2baf267d, 0x2ec5d479, 0x2ebd3fc4, 0x2bb854b4, 0x2bd3d53a, 0x2ea376d6, 

-	0x2e9adaee, 0x2bdcfcb0, 0x2bf868ed, 0x2e80fc6e, 0x2e785958, 0x2c01899e, 0x2c1ce181, 0x2e5e6556, 

-	0x2e55bb17, 0x2c25fb66, 0x2c413edf, 0x2e3bb1a4, 0x2e330042, 0x2c4a51f3, 0x2c6580f1, 0x2e18e16d, 

-	0x2e1028ed, 0x2c6e8d2e, 0x2c89a79f, 0x2df5f4c7, 0x2ded352f, 0x2c92ad01, 0x2cadb2d5, 0x2dd2ebc7, 

-	0x2dca251c, 0x2cb6b155, 0x2cd1a27b, 0x2dafc683, 0x2da6f8ca, 0x2cda9a14, 0x2cf5767c, 0x2d8c8510, 

-	0x2d83b04f, 0x2cfe6728, 0x2d192ec1, 0x2d692784, 0x2d604bc0, 0x2d22187a, 0x2d3ccb34, 0x2d45adf6

-};

-

-

-const int twidTab512[(8*6 + 32*6 + 128*6)/2] = {

-	0x40000000, 0x40000000, 0x40000000, 0x3b20187d, 

-	0x3ec50c7c, 0x3536238e, 0x2d412d41, 0x3b20187d, 

-	0x187d3b20, 0x187d3b20, 0x3536238e, 0xf3843ec5, 

-	0x00004000, 0x2d412d41, 0xd2bf2d41, 0xe7833b20, 

-	0x238e3536, 0xc13b0c7c, 0xd2bf2d41, 0x187d3b20, 

-	0xc4e0e783, 0xc4e0187d, 0x0c7c3ec5, 0xdc72caca, 

-

-	0x40000000, 0x40000000, 0x40000000, 0x3fb10645, 

-	0x3fec0323, 0x3f4e0964, 0x3ec50c7c, 0x3fb10645, 

-	0x3d3e1294, 0x3d3e1294, 0x3f4e0964, 0x39da1b5d, 

-	0x3b20187d, 0x3ec50c7c, 0x3536238e, 0x38711e2b, 

-	0x3e140f8c, 0x2f6b2afa, 0x3536238e, 0x3d3e1294, 

-	0x28993179, 0x31792899, 0x3c42158f, 0x20e736e5, 

-	0x2d412d41, 0x3b20187d, 0x187d3b20, 0x28993179, 

-	0x39da1b5d, 0x0f8c3e14, 0x238e3536, 0x38711e2b, 

-	0x06453fb1, 0x1e2b3871, 0x36e520e7, 0xfcdd3fec, 

-	0x187d3b20, 0x3536238e, 0xf3843ec5, 0x12943d3e, 

-	0x3367261f, 0xea713c42, 0x0c7c3ec5, 0x31792899, 

-	0xe1d53871, 0x06453fb1, 0x2f6b2afa, 0xd9e13367, 

-	0x00004000, 0x2d412d41, 0xd2bf2d41, 0xf9bb3fb1, 

-	0x2afa2f6b, 0xcc99261f, 0xf3843ec5, 0x28993179, 

-	0xc78f1e2b, 0xed6c3d3e, 0x261f3367, 0xc3be158f, 

-	0xe7833b20, 0x238e3536, 0xc13b0c7c, 0xe1d53871, 

-	0x20e736e5, 0xc0140323, 0xdc723536, 0x1e2b3871, 

-	0xc04ff9bb, 0xd7673179, 0x1b5d39da, 0xc1ecf074, 

-	0xd2bf2d41, 0x187d3b20, 0xc4e0e783, 0xce872899, 

-	0x158f3c42, 0xc91bdf19, 0xcaca238e, 0x12943d3e, 

-	0xce87d767, 0xc78f1e2b, 0x0f8c3e14, 0xd506d095, 

-	0xc4e0187d, 0x0c7c3ec5, 0xdc72caca, 0xc2c21294, 

-	0x09643f4e, 0xe4a3c626, 0xc13b0c7c, 0x06453fb1, 

-	0xed6cc2c2, 0xc04f0645, 0x03233fec, 0xf69cc0b2, 

-

-	0x40000000, 0x40000000, 0x40000000, 0x3ffb0192, 

-	0x3ffe00c9, 0x3ff4025b, 0x3fec0323, 0x3ffb0192, 

-	0x3fd304b5, 0x3fd304b5, 0x3ff4025b, 0x3f9c070d, 

-	0x3fb10645, 0x3fec0323, 0x3f4e0964, 0x3f8407d5, 

-	0x3fe103ec, 0x3eeb0bb6, 0x3f4e0964, 0x3fd304b5, 

-	0x3e710e05, 0x3f0e0af1, 0x3fc3057d, 0x3de2104f, 

-	0x3ec50c7c, 0x3fb10645, 0x3d3e1294, 0x3e710e05, 

-	0x3f9c070d, 0x3c8414d1, 0x3e140f8c, 0x3f8407d5, 

-	0x3bb61708, 0x3dae1111, 0x3f6a089c, 0x3ad21937, 

-	0x3d3e1294, 0x3f4e0964, 0x39da1b5d, 0x3cc51413, 

-	0x3f2f0a2a, 0x38cf1d79, 0x3c42158f, 0x3f0e0af1, 

-	0x37af1f8b, 0x3bb61708, 0x3eeb0bb6, 0x367c2192, 

-	0x3b20187d, 0x3ec50c7c, 0x3536238e, 0x3a8219ef, 

-	0x3e9c0d41, 0x33de257d, 0x39da1b5d, 0x3e710e05, 

-	0x3274275f, 0x392a1cc6, 0x3e440ec9, 0x30f82934, 

-	0x38711e2b, 0x3e140f8c, 0x2f6b2afa, 0x37af1f8b, 

-	0x3de2104f, 0x2dce2cb2, 0x36e520e7, 0x3dae1111, 

-	0x2c212e5a, 0x3612223d, 0x3d7711d3, 0x2a652ff1, 

-	0x3536238e, 0x3d3e1294, 0x28993179, 0x345324da, 

-	0x3d021354, 0x26c032ee, 0x3367261f, 0x3cc51413, 

-	0x24da3453, 0x3274275f, 0x3c8414d1, 0x22e635a5, 

-	0x31792899, 0x3c42158f, 0x20e736e5, 0x307629cd, 

-	0x3bfd164c, 0x1edc3811, 0x2f6b2afa, 0x3bb61708, 

-	0x1cc6392a, 0x2e5a2c21, 0x3b6c17c3, 0x1aa63a2f, 

-	0x2d412d41, 0x3b20187d, 0x187d3b20, 0x2c212e5a, 

-	0x3ad21937, 0x164c3bfd, 0x2afa2f6b, 0x3a8219ef, 

-	0x14133cc5, 0x29cd3076, 0x3a2f1aa6, 0x11d33d77, 

-	0x28993179, 0x39da1b5d, 0x0f8c3e14, 0x275f3274, 

-	0x39831c12, 0x0d413e9c, 0x261f3367, 0x392a1cc6, 

-	0x0af13f0e, 0x24da3453, 0x38cf1d79, 0x089c3f6a, 

-	0x238e3536, 0x38711e2b, 0x06453fb1, 0x223d3612, 

-	0x38111edc, 0x03ec3fe1, 0x20e736e5, 0x37af1f8b, 

-	0x01923ffb, 0x1f8b37af, 0x374b2039, 0xff373ffe, 

-	0x1e2b3871, 0x36e520e7, 0xfcdd3fec, 0x1cc6392a, 

-	0x367c2192, 0xfa833fc3, 0x1b5d39da, 0x3612223d, 

-	0xf82b3f84, 0x19ef3a82, 0x35a522e6, 0xf5d63f2f, 

-	0x187d3b20, 0x3536238e, 0xf3843ec5, 0x17083bb6, 

-	0x34c62434, 0xf1373e44, 0x158f3c42, 0x345324da, 

-	0xeeef3dae, 0x14133cc5, 0x33de257d, 0xecac3d02, 

-	0x12943d3e, 0x3367261f, 0xea713c42, 0x11113dae, 

-	0x32ee26c0, 0xe83d3b6c, 0x0f8c3e14, 0x3274275f, 

-	0xe6113a82, 0x0e053e71, 0x31f727fd, 0xe3ee3983, 

-	0x0c7c3ec5, 0x31792899, 0xe1d53871, 0x0af13f0e, 

-	0x30f82934, 0xdfc7374b, 0x09643f4e, 0x307629cd, 

-	0xddc33612, 0x07d53f84, 0x2ff12a65, 0xdbcc34c6, 

-	0x06453fb1, 0x2f6b2afa, 0xd9e13367, 0x04b53fd3, 

-	0x2ee32b8e, 0xd80331f7, 0x03233fec, 0x2e5a2c21, 

-	0xd6333076, 0x01923ffb, 0x2dce2cb2, 0xd4722ee3, 

-	0x00004000, 0x2d412d41, 0xd2bf2d41, 0xfe6e3ffb, 

-	0x2cb22dce, 0xd11d2b8e, 0xfcdd3fec, 0x2c212e5a, 

-	0xcf8a29cd, 0xfb4b3fd3, 0x2b8e2ee3, 0xce0927fd, 

-	0xf9bb3fb1, 0x2afa2f6b, 0xcc99261f, 0xf82b3f84, 

-	0x2a652ff1, 0xcb3a2434, 0xf69c3f4e, 0x29cd3076, 

-	0xc9ee223d, 0xf50f3f0e, 0x293430f8, 0xc8b52039, 

-	0xf3843ec5, 0x28993179, 0xc78f1e2b, 0xf1fb3e71, 

-	0x27fd31f7, 0xc67d1c12, 0xf0743e14, 0x275f3274, 

-	0xc57e19ef, 0xeeef3dae, 0x26c032ee, 0xc49417c3, 

-	0xed6c3d3e, 0x261f3367, 0xc3be158f, 0xebed3cc5, 

-	0x257d33de, 0xc2fe1354, 0xea713c42, 0x24da3453, 

-	0xc2521111, 0xe8f83bb6, 0x243434c6, 0xc1bc0ec9, 

-	0xe7833b20, 0x238e3536, 0xc13b0c7c, 0xe6113a82, 

-	0x22e635a5, 0xc0d10a2a, 0xe4a339da, 0x223d3612, 

-	0xc07c07d5, 0xe33a392a, 0x2192367c, 0xc03d057d, 

-	0xe1d53871, 0x20e736e5, 0xc0140323, 0xe07537af, 

-	0x2039374b, 0xc00200c9, 0xdf1936e5, 0x1f8b37af, 

-	0xc005fe6e, 0xddc33612, 0x1edc3811, 0xc01ffc14, 

-	0xdc723536, 0x1e2b3871, 0xc04ff9bb, 0xdb263453, 

-	0x1d7938cf, 0xc096f764, 0xd9e13367, 0x1cc6392a, 

-	0xc0f2f50f, 0xd8a13274, 0x1c123983, 0xc164f2bf, 

-	0xd7673179, 0x1b5d39da, 0xc1ecf074, 0xd6333076, 

-	0x1aa63a2f, 0xc289ee2d, 0xd5062f6b, 0x19ef3a82, 

-	0xc33bebed, 0xd3df2e5a, 0x19373ad2, 0xc403e9b4, 

-	0xd2bf2d41, 0x187d3b20, 0xc4e0e783, 0xd1a62c21, 

-	0x17c33b6c, 0xc5d1e55a, 0xd0952afa, 0x17083bb6, 

-	0xc6d6e33a, 0xcf8a29cd, 0x164c3bfd, 0xc7efe124, 

-	0xce872899, 0x158f3c42, 0xc91bdf19, 0xcd8c275f, 

-	0x14d13c84, 0xca5bdd1a, 0xcc99261f, 0x14133cc5, 

-	0xcbaddb26, 0xcbad24da, 0x13543d02, 0xcd12d940, 

-	0xcaca238e, 0x12943d3e, 0xce87d767, 0xc9ee223d, 

-	0x11d33d77, 0xd00fd59b, 0xc91b20e7, 0x11113dae, 

-	0xd1a6d3df, 0xc8511f8b, 0x104f3de2, 0xd34ed232, 

-	0xc78f1e2b, 0x0f8c3e14, 0xd506d095, 0xc6d61cc6, 

-	0x0ec93e44, 0xd6cccf08, 0xc6261b5d, 0x0e053e71, 

-	0xd8a1cd8c, 0xc57e19ef, 0x0d413e9c, 0xda83cc22, 

-	0xc4e0187d, 0x0c7c3ec5, 0xdc72caca, 0xc44a1708, 

-	0x0bb63eeb, 0xde6ec984, 0xc3be158f, 0x0af13f0e, 

-	0xe075c851, 0xc33b1413, 0x0a2a3f2f, 0xe287c731, 

-	0xc2c21294, 0x09643f4e, 0xe4a3c626, 0xc2521111, 

-	0x089c3f6a, 0xe6c9c52e, 0xc1ec0f8c, 0x07d53f84, 

-	0xe8f8c44a, 0xc18f0e05, 0x070d3f9c, 0xeb2fc37c, 

-	0xc13b0c7c, 0x06453fb1, 0xed6cc2c2, 0xc0f20af1, 

-	0x057d3fc3, 0xefb1c21e, 0xc0b20964, 0x04b53fd3, 

-	0xf1fbc18f, 0xc07c07d5, 0x03ec3fe1, 0xf44ac115, 

-	0xc04f0645, 0x03233fec, 0xf69cc0b2, 0xc02d04b5, 

-	0x025b3ff4, 0xf8f3c064, 0xc0140323, 0x01923ffb, 

-	0xfb4bc02d, 0xc0050192, 0x00c93ffe, 0xfda5c00c	

-};

-

-const int twidTab64[(4*6 + 16*6)/2] = {

-	0x40000000, 0x40000000, 0x40000000, 0x2d412d41, 

-	0x3b20187d, 0x187d3b20, 0x00004000, 0x2d412d41, 

-	0xd2bf2d41, 0xd2bf2d41, 0x187d3b20, 0xc4e0e783, 

-

-	0x40000000, 0x40000000, 0x40000000, 0x3ec50c7c, 

-	0x3fb10645, 0x3d3e1294, 0x3b20187d, 0x3ec50c7c, 

-	0x3536238e, 0x3536238e, 0x3d3e1294, 0x28993179, 

-	0x2d412d41, 0x3b20187d, 0x187d3b20, 0x238e3536, 

-	0x38711e2b, 0x06453fb1, 0x187d3b20, 0x3536238e, 

-	0xf3843ec5, 0x0c7c3ec5, 0x31792899, 0xe1d53871, 

-	0x00004000, 0x2d412d41, 0xd2bf2d41, 0xf3843ec5, 

-	0x28993179, 0xc78f1e2b, 0xe7833b20, 0x238e3536, 

-	0xc13b0c7c, 0xdc723536, 0x1e2b3871, 0xc04ff9bb, 

-	0xd2bf2d41, 0x187d3b20, 0xc4e0e783, 0xcaca238e, 

-	0x12943d3e, 0xce87d767, 0xc4e0187d, 0x0c7c3ec5, 

-	0xdc72caca, 0xc13b0c7c, 0x06453fb1, 0xed6cc2c2 

-};

-

-#elif defined ARMV7Neon

-/* 

- *  Q29 for 128 and 1024 

- *

- * for (i = 0; i < num/4; i++) {

- *   angle = (i + 0.125) * M_PI / num;

- *   x = cos(angle) * (1 << 29);

- *   x = sin(angle) * (1 << 29);

- * 

- *   angle = (num/2 - 1 - i + 0.125) * M_PI / num;

- *   x = cos(angle) * (1 << 29);

- *   x = sin(angle) * (1 << 29);

- * }

- */

-const int cossintab[128 + 1024] = {

-	/* 128 */

+#include "aac_rom.h"
+
+#if defined (ARMV5E) && !defined (ARMV7Neon)
+
+/* 
+ *  Q30 for 128 and 1024 
+ *
+ * for (i = 0; i < num/4; i++) {
+ *   angle = (i + 0.125) * M_PI / num;
+ *   x = cos(angle) * (1 << 30);
+ *   x = sin(angle) * (1 << 30);
+ * 
+ *   angle = (num/2 - 1 - i + 0.125) * M_PI / num;
+ *   x = cos(angle) * (1 << 30);
+ *   x = sin(angle) * (1 << 30);
+ * }
+ */
+const int cossintab[128 + 1024] = {
+	/* 128 */
+	0x3fffec43, 0x003243f1, 0x015fd4d2, 0x3ffc38d1, 0x3ff9c13a, 0x01c454f5, 0x02f1b755, 0x3feea776, 
+	0x3fe9b8a9, 0x03562038, 0x0483259d, 0x3fd73a4a, 0x3fcfd50b, 0x04e767c5, 0x0613e1c5, 0x3fb5f4ea, 
+	0x3fac1a5b, 0x0677edbb, 0x07a3adff, 0x3f8adc77, 0x3f7e8e1e, 0x08077457, 0x09324ca7, 0x3f55f796, 
+	0x3f473759, 0x0995bdfd, 0x0abf8043, 0x3f174e70, 0x3f061e95, 0x0b228d42, 0x0c4b0b94, 0x3eceeaad, 
+	0x3ebb4ddb, 0x0cada4f5, 0x0dd4b19a, 0x3e7cd778, 0x3e66d0b4, 0x0e36c82a, 0x0f5c35a3, 0x3e212179, 
+	0x3e08b42a, 0x0fbdba40, 0x10e15b4e, 0x3dbbd6d4, 0x3da106bd, 0x11423ef0, 0x1263e699, 0x3d4d0728, 
+	0x3d2fd86c, 0x12c41a4f, 0x13e39be9, 0x3cd4c38b, 0x3cb53aaa, 0x144310dd, 0x15604013, 0x3c531e88, 
+	0x3c314060, 0x15bee78c, 0x16d99864, 0x3bc82c1f, 0x3ba3fde7, 0x173763c9, 0x184f6aab, 0x3b3401bb, 
+	0x3b0d8909, 0x18ac4b87, 0x19c17d44, 0x3a96b636, 0x3a6df8f8, 0x1a1d6544, 0x1b2f971e, 0x39f061d2, 
+	0x39c5664f, 0x1b8a7815, 0x1c997fc4, 0x39411e33, 0x3913eb0e, 0x1cf34baf, 0x1dfeff67, 0x38890663, 
+	0x3859a292, 0x1e57a86d, 0x1f5fdee6, 0x37c836c2, 0x3796a996, 0x1fb7575c, 0x20bbe7d8, 0x36fecd0e, 
+	0x36cb1e2a, 0x21122240, 0x2212e492, 0x362ce855, 0x35f71fb1, 0x2267d3a0, 0x2364a02e, 0x3552a8f4, 
+	0x351acedd, 0x23b836ca, 0x24b0e699, 0x34703095, 0x34364da6, 0x250317df, 0x25f78497, 0x3385a222, 
+	0x3349bf48, 0x264843d9, 0x273847c8, 0x329321c7, 0x32554840, 0x27878893, 0x2872feb6, 0x3198d4ea, 
+	0x31590e3e, 0x28c0b4d2, 0x29a778db, 0x3096e223, 0x30553828, 0x29f3984c, 0x2ad586a3, 0x2f8d713a, 
+	0x2f49ee0f, 0x2b2003ac, 0x2bfcf97c, 0x2e7cab1c, 0x2e37592c, 0x2c45c8a0, 0x2d1da3d5, 0x2d64b9da, 
+	/* 1024 */
+	0x3fffffb1, 0x0006487f, 0x002bfb74, 0x3ffff0e3, 0x3fffe705, 0x00388c6e, 0x005e3f4c, 0x3fffba9b, 
+	0x3fffa6de, 0x006ad03b, 0x009082ea, 0x3fff5cd8, 0x3fff3f3c, 0x009d13c5, 0x00c2c62f, 0x3ffed79b, 
+	0x3ffeb021, 0x00cf56ef, 0x00f508fc, 0x3ffe2ae5, 0x3ffdf98c, 0x01019998, 0x01274b31, 0x3ffd56b5, 
+	0x3ffd1b7e, 0x0133dba3, 0x01598cb1, 0x3ffc5b0c, 0x3ffc15f7, 0x01661cf0, 0x018bcd5b, 0x3ffb37ec, 
+	0x3ffae8f9, 0x01985d60, 0x01be0d11, 0x3ff9ed53, 0x3ff99483, 0x01ca9cd4, 0x01f04bb4, 0x3ff87b44, 
+	0x3ff81896, 0x01fcdb2e, 0x02228924, 0x3ff6e1bf, 0x3ff67534, 0x022f184d, 0x0254c544, 0x3ff520c5, 
+	0x3ff4aa5d, 0x02615414, 0x0286fff3, 0x3ff33858, 0x3ff2b813, 0x02938e62, 0x02b93914, 0x3ff12878, 
+	0x3ff09e56, 0x02c5c71a, 0x02eb7086, 0x3feef126, 0x3fee5d28, 0x02f7fe1c, 0x031da62b, 0x3fec9265, 
+	0x3febf48b, 0x032a3349, 0x034fd9e5, 0x3fea0c35, 0x3fe96480, 0x035c6682, 0x03820b93, 0x3fe75e98, 
+	0x3fe6ad08, 0x038e97a9, 0x03b43b17, 0x3fe48990, 0x3fe3ce26, 0x03c0c69e, 0x03e66852, 0x3fe18d1f, 
+	0x3fe0c7da, 0x03f2f342, 0x04189326, 0x3fde6945, 0x3fdd9a27, 0x04251d77, 0x044abb73, 0x3fdb1e06, 
+	0x3fda450f, 0x0457451d, 0x047ce11a, 0x3fd7ab64, 0x3fd6c894, 0x04896a16, 0x04af03fc, 0x3fd4115f, 
+	0x3fd324b7, 0x04bb8c42, 0x04e123fa, 0x3fd04ffc, 0x3fcf597c, 0x04edab83, 0x051340f6, 0x3fcc673b, 
+	0x3fcb66e4, 0x051fc7b9, 0x05455ad1, 0x3fc8571f, 0x3fc74cf3, 0x0551e0c7, 0x0577716b, 0x3fc41fac, 
+	0x3fc30baa, 0x0583f68c, 0x05a984a6, 0x3fbfc0e3, 0x3fbea30c, 0x05b608eb, 0x05db9463, 0x3fbb3ac7, 
+	0x3fba131b, 0x05e817c3, 0x060da083, 0x3fb68d5b, 0x3fb55bdc, 0x061a22f7, 0x063fa8e7, 0x3fb1b8a2, 
+	0x3fb07d50, 0x064c2a67, 0x0671ad71, 0x3facbc9f, 0x3fab777b, 0x067e2df5, 0x06a3ae00, 0x3fa79954, 
+	0x3fa64a5f, 0x06b02d81, 0x06d5aa77, 0x3fa24ec6, 0x3fa0f600, 0x06e228ee, 0x0707a2b7, 0x3f9cdcf7, 
+	0x3f9b7a62, 0x0714201b, 0x073996a1, 0x3f9743eb, 0x3f95d787, 0x074612eb, 0x076b8616, 0x3f9183a5, 
+	0x3f900d72, 0x0778013d, 0x079d70f7, 0x3f8b9c28, 0x3f8a1c29, 0x07a9eaf5, 0x07cf5726, 0x3f858d79, 
+	0x3f8403ae, 0x07dbcff2, 0x08013883, 0x3f7f579b, 0x3f7dc405, 0x080db016, 0x083314f1, 0x3f78fa92, 
+	0x3f775d31, 0x083f8b43, 0x0864ec4f, 0x3f727661, 0x3f70cf38, 0x08716159, 0x0896be80, 0x3f6bcb0e, 
+	0x3f6a1a1c, 0x08a3323a, 0x08c88b65, 0x3f64f89b, 0x3f633de2, 0x08d4fdc6, 0x08fa52de, 0x3f5dff0e, 
+	0x3f5c3a8f, 0x0906c3e0, 0x092c14ce, 0x3f56de6a, 0x3f551026, 0x09388469, 0x095dd116, 0x3f4f96b4, 
+	0x3f4dbeac, 0x096a3f42, 0x098f8796, 0x3f4827f0, 0x3f464626, 0x099bf44c, 0x09c13831, 0x3f409223, 
+	0x3f3ea697, 0x09cda368, 0x09f2e2c7, 0x3f38d552, 0x3f36e006, 0x09ff4c78, 0x0a24873a, 0x3f30f181, 
+	0x3f2ef276, 0x0a30ef5e, 0x0a56256c, 0x3f28e6b6, 0x3f26ddec, 0x0a628bfa, 0x0a87bd3d, 0x3f20b4f5, 
+	0x3f1ea26e, 0x0a94222f, 0x0ab94e8f, 0x3f185c43, 0x3f164001, 0x0ac5b1dc, 0x0aead944, 0x3f0fdca5, 
+	0x3f0db6a9, 0x0af73ae5, 0x0b1c5d3d, 0x3f073621, 0x3f05066d, 0x0b28bd2a, 0x0b4dda5c, 0x3efe68bc, 
+	0x3efc2f50, 0x0b5a388d, 0x0b7f5081, 0x3ef5747b, 0x3ef3315a, 0x0b8bacf0, 0x0bb0bf8f, 0x3eec5965, 
+	0x3eea0c8e, 0x0bbd1a33, 0x0be22766, 0x3ee3177e, 0x3ee0c0f4, 0x0bee8038, 0x0c1387e9, 0x3ed9aecc, 
+	0x3ed74e91, 0x0c1fdee1, 0x0c44e0f9, 0x3ed01f55, 0x3ecdb56a, 0x0c513610, 0x0c763278, 0x3ec66920, 
+	0x3ec3f585, 0x0c8285a5, 0x0ca77c47, 0x3ebc8c31, 0x3eba0ee9, 0x0cb3cd84, 0x0cd8be47, 0x3eb2888f, 
+	0x3eb0019c, 0x0ce50d8c, 0x0d09f85b, 0x3ea85e41, 0x3ea5cda3, 0x0d1645a0, 0x0d3b2a64, 0x3e9e0d4c, 
+	0x3e9b7306, 0x0d4775a1, 0x0d6c5443, 0x3e9395b7, 0x3e90f1ca, 0x0d789d71, 0x0d9d75db, 0x3e88f788, 
+	0x3e8649f5, 0x0da9bcf2, 0x0dce8f0d, 0x3e7e32c6, 0x3e7b7b90, 0x0ddad406, 0x0dff9fba, 0x3e734778, 
+	0x3e70869f, 0x0e0be28e, 0x0e30a7c5, 0x3e6835a4, 0x3e656b2b, 0x0e3ce86b, 0x0e61a70f, 0x3e5cfd51, 
+	0x3e5a2939, 0x0e6de580, 0x0e929d7a, 0x3e519e86, 0x3e4ec0d1, 0x0e9ed9af, 0x0ec38ae8, 0x3e46194a, 
+	0x3e4331fa, 0x0ecfc4d9, 0x0ef46f3b, 0x3e3a6da4, 0x3e377cbb, 0x0f00a6df, 0x0f254a53, 0x3e2e9b9c, 
+	0x3e2ba11b, 0x0f317fa5, 0x0f561c15, 0x3e22a338, 0x3e1f9f21, 0x0f624f0c, 0x0f86e460, 0x3e168480, 
+	0x3e1376d5, 0x0f9314f5, 0x0fb7a317, 0x3e0a3f7b, 0x3e07283f, 0x0fc3d143, 0x0fe8581d, 0x3dfdd432, 
+	0x3dfab365, 0x0ff483d7, 0x10190352, 0x3df142ab, 0x3dee1851, 0x10252c94, 0x1049a49a, 0x3de48aef, 
+	0x3de15708, 0x1055cb5b, 0x107a3bd5, 0x3dd7ad05, 0x3dd46f94, 0x1086600e, 0x10aac8e6, 0x3dcaa8f5, 
+	0x3dc761fc, 0x10b6ea90, 0x10db4baf, 0x3dbd7ec7, 0x3dba2e48, 0x10e76ac3, 0x110bc413, 0x3db02e84, 
+	0x3dacd481, 0x1117e088, 0x113c31f3, 0x3da2b834, 0x3d9f54af, 0x11484bc2, 0x116c9531, 0x3d951bde, 
+	0x3d91aed9, 0x1178ac53, 0x119cedaf, 0x3d87598c, 0x3d83e309, 0x11a9021d, 0x11cd3b50, 0x3d797145, 
+	0x3d75f147, 0x11d94d02, 0x11fd7df6, 0x3d6b6313, 0x3d67d99b, 0x12098ce5, 0x122db583, 0x3d5d2efe, 
+	0x3d599c0e, 0x1239c1a7, 0x125de1da, 0x3d4ed50f, 0x3d4b38aa, 0x1269eb2b, 0x128e02dc, 0x3d40554e, 
+	0x3d3caf76, 0x129a0954, 0x12be186c, 0x3d31afc5, 0x3d2e007c, 0x12ca1c03, 0x12ee226c, 0x3d22e47c, 
+	0x3d1f2bc5, 0x12fa231b, 0x131e20c0, 0x3d13f37e, 0x3d10315a, 0x132a1e7e, 0x134e1348, 0x3d04dcd2, 
+	0x3d011145, 0x135a0e0e, 0x137df9e7, 0x3cf5a082, 0x3cf1cb8e, 0x1389f1af, 0x13add481, 0x3ce63e98, 
+	0x3ce2603f, 0x13b9c943, 0x13dda2f7, 0x3cd6b71e, 0x3cd2cf62, 0x13e994ab, 0x140d652c, 0x3cc70a1c, 
+	0x3cc318ff, 0x141953cb, 0x143d1b02, 0x3cb7379c, 0x3cb33d22, 0x14490685, 0x146cc45c, 0x3ca73fa9, 
+	0x3ca33bd3, 0x1478acbc, 0x149c611d, 0x3c97224c, 0x3c93151d, 0x14a84652, 0x14cbf127, 0x3c86df8e, 
+	0x3c82c909, 0x14d7d32a, 0x14fb745e, 0x3c76777b, 0x3c7257a2, 0x15075327, 0x152aeaa3, 0x3c65ea1c, 
+	0x3c61c0f1, 0x1536c62b, 0x155a53d9, 0x3c55377b, 0x3c510501, 0x15662c18, 0x1589afe3, 0x3c445fa2, 
+	0x3c4023dd, 0x159584d3, 0x15b8fea4, 0x3c33629d, 0x3c2f1d8e, 0x15c4d03e, 0x15e83fff, 0x3c224075, 
+	0x3c1df21f, 0x15f40e3a, 0x161773d6, 0x3c10f935, 0x3c0ca19b, 0x16233eac, 0x16469a0d, 0x3bff8ce8, 
+	0x3bfb2c0c, 0x16526176, 0x1675b286, 0x3bedfb99, 0x3be9917e, 0x1681767c, 0x16a4bd25, 0x3bdc4552, 
+	0x3bd7d1fa, 0x16b07d9f, 0x16d3b9cc, 0x3bca6a1d, 0x3bc5ed8d, 0x16df76c3, 0x1702a85e, 0x3bb86a08, 
+	0x3bb3e440, 0x170e61cc, 0x173188be, 0x3ba6451b, 0x3ba1b620, 0x173d3e9b, 0x17605ad0, 0x3b93fb63, 
+	0x3b8f6337, 0x176c0d15, 0x178f1e76, 0x3b818ceb, 0x3b7ceb90, 0x179acd1c, 0x17bdd394, 0x3b6ef9be, 
+	0x3b6a4f38, 0x17c97e93, 0x17ec7a0d, 0x3b5c41e8, 0x3b578e39, 0x17f8215e, 0x181b11c4, 0x3b496574, 
+	0x3b44a8a0, 0x1826