Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2004-2010 NXP Software
      3  * Copyright (C) 2010 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 /**********************************************************************************
     19    INCLUDE FILES
     20 ***********************************************************************************/
     21 
     22 #include "LVM_Types.h"
     23 #include "LVM_Macros.h"
     24 #include "VectorArithmetic.h"
     25 
     26 /**********************************************************************************
     27    FUNCTION DelayAllPass_32x32
     28 ***********************************************************************************/
     29 
     30 void DelayAllPass_Sat_32x16To32(  LVM_INT32  *delay,                    /* Delay buffer */
     31                                   LVM_UINT16 size,                      /* Delay size */
     32                                   LVM_INT16 coeff,                      /* All pass filter coefficient */
     33                                   LVM_UINT16 DelayOffset,               /* Simple delay offset */
     34                                   LVM_UINT16 *pAllPassOffset,           /* All pass filter delay offset */
     35                                   LVM_INT32  *dst,                      /* Source/destination */
     36                                   LVM_INT16 n)                          /* Number of  samples */
     37 {
     38     LVM_INT16   i;
     39     LVM_UINT16   AllPassOffset = *pAllPassOffset;
     40     LVM_INT32    temp;
     41     LVM_INT32    a,b,c;
     42 
     43     for (i = 0; i < n; i++)
     44     {
     45 
     46         MUL32x16INTO32(delay[AllPassOffset], coeff, temp, 15)
     47         a = temp;
     48         b = delay[DelayOffset];
     49         DelayOffset++;
     50 
     51         c = a + b;
     52         if ((((c ^ a) & (c ^ b)) >> 31) != 0)  /* overflow / underflow */
     53         {
     54             if(a < 0)
     55             {
     56                 c = 0x80000000l;
     57             }
     58             else
     59             {
     60                 c = 0x7FFFFFFFl;
     61             }
     62         }
     63         *dst = c;
     64         dst++;
     65 
     66 
     67         MUL32x16INTO32(c, -coeff, temp, 15)
     68         a = temp;
     69         b = delay[AllPassOffset];
     70         c = a + b;
     71         if ((((c ^ a) & (c ^ b)) >> 31)!=0)  /* overflow / underflow */
     72         {
     73             if(a < 0)
     74             {
     75                 c = 0x80000000l;
     76             }
     77             else
     78             {
     79                 c = 0x7FFFFFFFl;
     80             }
     81         }
     82         delay[AllPassOffset] = c;
     83         AllPassOffset++;
     84 
     85         /* Make the delay buffer a circular buffer */
     86         if (DelayOffset >= size)
     87         {
     88             DelayOffset = 0;
     89         }
     90 
     91         if (AllPassOffset >= size)
     92         {
     93             AllPassOffset = 0;
     94         }
     95     }
     96 
     97     /* Update the offset */
     98     *pAllPassOffset = AllPassOffset;
     99 
    100     return;
    101 }
    102 
    103 /**********************************************************************************/
    104 
    105