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 
DelayAllPass_Sat_32x16To32(LVM_INT32 * delay,LVM_UINT16 size,LVM_INT16 coeff,LVM_UINT16 DelayOffset,LVM_UINT16 * pAllPassOffset,LVM_INT32 * dst,LVM_INT16 n)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         MUL32x16INTO32(c, -coeff, temp, 15)
67         a = temp;
68         b = delay[AllPassOffset];
69         c = a + b;
70         if ((((c ^ a) & (c ^ b)) >> 31)!=0)  /* overflow / underflow */
71         {
72             if(a < 0)
73             {
74                 c = 0x80000000L;
75             }
76             else
77             {
78                 c = 0x7FFFFFFFL;
79             }
80         }
81         delay[AllPassOffset] = c;
82         AllPassOffset++;
83 
84         /* Make the delay buffer a circular buffer */
85         if (DelayOffset >= size)
86         {
87             DelayOffset = 0;
88         }
89 
90         if (AllPassOffset >= size)
91         {
92             AllPassOffset = 0;
93         }
94     }
95 
96     /* Update the offset */
97     *pAllPassOffset = AllPassOffset;
98 
99     return;
100 }
101 
102 /**********************************************************************************/
103 
104