Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / low_pass_filt_7k.cpp
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.173
22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31
32
33
34  Filename: low_pass_filt_7k.cpp
35
36 ------------------------------------------------------------------------------
37  INPUT AND OUTPUT DEFINITIONS
38
39      int16 signal[],             input signal / output is divided by 16
40      int16 lg,                   lenght of signal
41      int16 mem[]                 in/out: memory (size=30)
42      int16 x[]                   scratch mem ( size= 60)
43
44 ------------------------------------------------------------------------------
45  FUNCTION DESCRIPTION
46
47         15th order high pass 7kHz FIR filter
48
49
50 ------------------------------------------------------------------------------
51  REQUIREMENTS
52
53
54 ------------------------------------------------------------------------------
55  REFERENCES
56
57 ------------------------------------------------------------------------------
58  PSEUDO-CODE
59
60 ------------------------------------------------------------------------------
61 */
62
63
64 /*----------------------------------------------------------------------------
65 ; INCLUDES
66 ----------------------------------------------------------------------------*/
67
68 #include "pv_amr_wb_type_defs.h"
69 #include "pvamrwbdecoder_basic_op.h"
70 #include "pvamrwbdecoder_cnst.h"
71 #include "pvamrwbdecoder_acelp.h"
72
73 /*----------------------------------------------------------------------------
74 ; MACROS
75 ; Define module specific macros here
76 ----------------------------------------------------------------------------*/
77
78
79 /*----------------------------------------------------------------------------
80 ; DEFINES
81 ; Include all pre-processor statements here. Include conditional
82 ; compile variables also.
83 ----------------------------------------------------------------------------*/
84 #define L_FIR 30
85
86 /*----------------------------------------------------------------------------
87 ; LOCAL FUNCTION DEFINITIONS
88 ; Function Prototype declaration
89 ----------------------------------------------------------------------------*/
90
91 /*----------------------------------------------------------------------------
92 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
93 ; Variable declaration - defined here and used outside this module
94 ----------------------------------------------------------------------------*/
95 const int16 fir_7k[L_FIR+1] =
96 {
97     -21, 47, -89, 146, -203,
98     229, -177, 0, 335, -839,
99     1485, -2211, 2931, -3542, 3953,
100     28682, 3953, -3542, 2931, -2211,
101     1485, -839, 335, 0, -177,
102     229, -203, 146, -89, 47,
103     -21
104 };
105
106 /*----------------------------------------------------------------------------
107 ; EXTERNAL FUNCTION REFERENCES
108 ; Declare functions defined elsewhere and referenced in this module
109 ----------------------------------------------------------------------------*/
110
111 /*----------------------------------------------------------------------------
112 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
113 ; Declare variables used in this module but defined elsewhere
114 ----------------------------------------------------------------------------*/
115
116 /*----------------------------------------------------------------------------
117 ; FUNCTION CODE
118 ----------------------------------------------------------------------------*/
119
120
121 void low_pass_filt_7k_init(int16 mem[])            /* mem[30] */
122 {
123     pv_memset((void *)mem, 0, (L_FIR)*sizeof(*mem));
124
125     return;
126 }
127
128
129 /*----------------------------------------------------------------------------
130 ; FUNCTION CODE
131 ----------------------------------------------------------------------------*/
132
133
134 void low_pass_filt_7k(
135     int16 signal[],                      /* input:  signal                  */
136     int16 lg,                            /* input:  length of input         */
137     int16 mem[],                         /* in/out: memory (size=30)        */
138     int16 x[]
139 )
140 {
141     int16 i, j;
142     int32 L_tmp1;
143     int32 L_tmp2;
144     int32 L_tmp3;
145     int32 L_tmp4;
146
147     pv_memcpy((void *)x, (void *)mem, (L_FIR)*sizeof(*x));
148
149     for (i = 0; i < lg >> 2; i++)
150     {
151         x[(i<<2) + L_FIR    ] = signal[(i<<2)];
152         x[(i<<2) + L_FIR + 1] = signal[(i<<2)+1];
153         x[(i<<2) + L_FIR + 2] = signal[(i<<2)+2];
154         x[(i<<2) + L_FIR + 3] = signal[(i<<2)+3];
155
156         L_tmp1 = fxp_mac_16by16(x[(i<<2)] + signal[(i<<2)], fir_7k[0], 0x00004000);
157         L_tmp2 = fxp_mac_16by16(x[(i<<2)+1] + signal[(i<<2)+1], fir_7k[0], 0x00004000);
158         L_tmp3 = fxp_mac_16by16(x[(i<<2)+2] + signal[(i<<2)+2], fir_7k[0], 0x00004000);
159         L_tmp4 = fxp_mac_16by16(x[(i<<2)+3] + signal[(i<<2)+3], fir_7k[0], 0x00004000);
160
161         for (j = 1; j < L_FIR - 1; j += 4)
162         {
163
164
165             int16 tmp1 = x[(i<<2)+j  ];
166             int16 tmp2 = x[(i<<2)+j+1];
167             int16 tmp3 = x[(i<<2)+j+2];
168
169             L_tmp1 = fxp_mac_16by16(tmp1, fir_7k[j  ], L_tmp1);
170             L_tmp2 = fxp_mac_16by16(tmp2, fir_7k[j  ], L_tmp2);
171             L_tmp1 = fxp_mac_16by16(tmp2, fir_7k[j+1], L_tmp1);
172             L_tmp2 = fxp_mac_16by16(tmp3, fir_7k[j+1], L_tmp2);
173             L_tmp3 = fxp_mac_16by16(tmp3, fir_7k[j  ], L_tmp3);
174             L_tmp1 = fxp_mac_16by16(tmp3, fir_7k[j+2], L_tmp1);
175
176             tmp1 = x[(i<<2)+j+3];
177             tmp2 = x[(i<<2)+j+4];
178
179             L_tmp2 = fxp_mac_16by16(tmp1, fir_7k[j+2], L_tmp2);
180             L_tmp4 = fxp_mac_16by16(tmp1, fir_7k[j  ], L_tmp4);
181             L_tmp3 = fxp_mac_16by16(tmp1, fir_7k[j+1], L_tmp3);
182             L_tmp1 = fxp_mac_16by16(tmp1, fir_7k[j+3], L_tmp1);
183             L_tmp2 = fxp_mac_16by16(tmp2, fir_7k[j+3], L_tmp2);
184             L_tmp4 = fxp_mac_16by16(tmp2, fir_7k[j+1], L_tmp4);
185             L_tmp3 = fxp_mac_16by16(tmp2, fir_7k[j+2], L_tmp3);
186
187             tmp1 = x[(i<<2)+j+5];
188             tmp2 = x[(i<<2)+j+6];
189
190             L_tmp4 = fxp_mac_16by16(tmp1, fir_7k[j+2], L_tmp4);
191             L_tmp3 = fxp_mac_16by16(tmp1, fir_7k[j+3], L_tmp3);
192             L_tmp4 = fxp_mac_16by16(tmp2, fir_7k[j+3], L_tmp4);
193
194         }
195
196         L_tmp1 = fxp_mac_16by16(x[(i<<2)+j  ], fir_7k[j  ], L_tmp1);
197         L_tmp2 = fxp_mac_16by16(x[(i<<2)+j+1], fir_7k[j  ], L_tmp2);
198         L_tmp3 = fxp_mac_16by16(x[(i<<2)+j+2], fir_7k[j  ], L_tmp3);
199         L_tmp4 = fxp_mac_16by16(x[(i<<2)+j+3], fir_7k[j  ], L_tmp4);
200
201         signal[(i<<2)] = (int16)(L_tmp1 >> 15);
202         signal[(i<<2)+1] = (int16)(L_tmp2 >> 15);
203         signal[(i<<2)+2] = (int16)(L_tmp3 >> 15);
204         signal[(i<<2)+3] = (int16)(L_tmp4 >> 15);
205
206     }
207
208     pv_memcpy((void *)mem, (void *)(x + lg), (L_FIR)*sizeof(*mem));
209
210     return;
211 }
212