Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / band_pass_6k_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: band_pass_6k_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 band pass 6kHz to 7kHz FIR filter.
48
49    frequency:  4kHz   5kHz  5.5kHz  6kHz  6.5kHz 7kHz  7.5kHz  8kHz
50    dB loss:   -60dB  -45dB  -13dB   -3dB   0dB   -3dB  -13dB  -45dB
51
52
53 ------------------------------------------------------------------------------
54  REQUIREMENTS
55
56
57 ------------------------------------------------------------------------------
58  REFERENCES
59
60 ------------------------------------------------------------------------------
61  PSEUDO-CODE
62
63 ------------------------------------------------------------------------------
64 */
65
66
67 /*----------------------------------------------------------------------------
68 ; INCLUDES
69 ----------------------------------------------------------------------------*/
70
71
72 #include "pv_amr_wb_type_defs.h"
73 #include "pvamrwbdecoder_basic_op.h"
74 #include "pvamrwbdecoder_acelp.h"
75 #include "pvamrwbdecoder_cnst.h"
76
77 /*----------------------------------------------------------------------------
78 ; MACROS
79 ; Define module specific macros here
80 ----------------------------------------------------------------------------*/
81
82
83 /*----------------------------------------------------------------------------
84 ; DEFINES
85 ; Include all pre-processor statements here. Include conditional
86 ; compile variables also.
87 ----------------------------------------------------------------------------*/
88
89 #define L_FIR 30
90
91 /*----------------------------------------------------------------------------
92 ; LOCAL FUNCTION DEFINITIONS
93 ; Function Prototype declaration
94 ----------------------------------------------------------------------------*/
95
96 /*----------------------------------------------------------------------------
97 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
98 ; Variable declaration - defined here and used outside this module
99 ----------------------------------------------------------------------------*/
100
101 /* filter coefficients (gain=4.0) */
102
103 const int16 fir_6k_7k[L_FIR] =
104 {
105     -32,     47,     32,    -27,
106     -369,   1122,  -1421,      0,
107     3798,  -8880,  12349, -10984,
108     3548,   7766, -18001,
109     22118,
110     -18001,   7766,   3548, -10984,
111     12349,  -8880,   3798,      0,
112     -1421,   1122,   -369,    -27,
113     32,     47
114 };
115
116 /*----------------------------------------------------------------------------
117 ; EXTERNAL FUNCTION REFERENCES
118 ; Declare functions defined elsewhere and referenced in this module
119 ----------------------------------------------------------------------------*/
120
121 /*----------------------------------------------------------------------------
122 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
123 ; Declare variables used in this module but defined elsewhere
124 ----------------------------------------------------------------------------*/
125
126 /*----------------------------------------------------------------------------
127 ; FUNCTION CODE
128 ----------------------------------------------------------------------------*/
129
130 void band_pass_6k_7k_init(int16 mem[])         /* mem[30] */
131 {
132     pv_memset((void *)mem, 0, L_FIR*sizeof(*mem));
133 }
134
135
136 /*----------------------------------------------------------------------------
137 ; FUNCTION CODE
138 ----------------------------------------------------------------------------*/
139
140
141 void band_pass_6k_7k(
142     int16 signal[],                      /* input:  signal                  */
143     int16 lg,                            /* input:  length of input         */
144     int16 mem[],                         /* in/out: memory (size=30)        */
145     int16 x[]
146 )
147 {
148     int16 i, j;
149     int32 L_tmp1;
150     int32 L_tmp2;
151     int32 L_tmp3;
152     int32 L_tmp4;
153
154     int16 *pt_sign = signal;
155
156     pv_memcpy((void *)x, (void *)mem, L_FIR*sizeof(*x));
157
158
159     for (i = 0; i < lg >> 2; i++)
160     {
161
162         x[(i<<2) + L_FIR    ] = *(pt_sign) >> 2;        /* gain of filter = 4 */
163         x[(i<<2) + L_FIR + 1] = *(pt_sign + 1) >> 2;    /* gain of filter = 4 */
164         x[(i<<2) + L_FIR + 2] = *(pt_sign + 2) >> 2;    /* gain of filter = 4 */
165         x[(i<<2) + L_FIR + 3] = *(pt_sign + 3) >> 2;    /* gain of filter = 4 */
166
167         L_tmp1 = 0x00004000;
168         L_tmp2 = 0x00004000;
169         L_tmp3 = 0x00004000;
170         L_tmp4 = 0x00004000;
171
172         L_tmp1 -= ((int32)x[(i<<2)+L_FIR  ] << 5);
173         L_tmp2 -= ((int32)x[(i<<2)+L_FIR+1] << 5);
174         L_tmp3 -= ((int32)x[(i<<2)+L_FIR+2] << 5);
175         L_tmp4 -= ((int32)x[(i<<2)+L_FIR+3] << 5);
176
177         L_tmp1 -= ((int32)x[(i<<2)] << 5);
178         L_tmp2 -= ((int32)x[(i<<2)+1] << 5);
179         L_tmp3 -= ((int32)x[(i<<2)+2] << 5);
180         L_tmp4 -= ((int32)x[(i<<2)+3] << 5);
181
182
183         for (j = 1; j < L_FIR - 1; j += 4)
184         {
185             int16 tmp1 = x[(i<<2)+j  ];
186             int16 tmp2 = x[(i<<2)+j+1];
187             int16 tmp3 = x[(i<<2)+j+2];
188
189             L_tmp1 = fxp_mac_16by16(tmp1, fir_6k_7k[j  ], L_tmp1);
190             L_tmp2 = fxp_mac_16by16(tmp2, fir_6k_7k[j  ], L_tmp2);
191             L_tmp1 = fxp_mac_16by16(tmp2, fir_6k_7k[j+1], L_tmp1);
192             L_tmp2 = fxp_mac_16by16(tmp3, fir_6k_7k[j+1], L_tmp2);
193             L_tmp3 = fxp_mac_16by16(tmp3, fir_6k_7k[j  ], L_tmp3);
194             L_tmp1 = fxp_mac_16by16(tmp3, fir_6k_7k[j+2], L_tmp1);
195
196             tmp1 = x[(i<<2)+j+3];
197             tmp2 = x[(i<<2)+j+4];
198
199             L_tmp2 = fxp_mac_16by16(tmp1, fir_6k_7k[j+2], L_tmp2);
200             L_tmp4 = fxp_mac_16by16(tmp1, fir_6k_7k[j  ], L_tmp4);
201             L_tmp3 = fxp_mac_16by16(tmp1, fir_6k_7k[j+1], L_tmp3);
202             L_tmp1 = fxp_mac_16by16(tmp1, fir_6k_7k[j+3], L_tmp1);
203             L_tmp2 = fxp_mac_16by16(tmp2, fir_6k_7k[j+3], L_tmp2);
204             L_tmp4 = fxp_mac_16by16(tmp2, fir_6k_7k[j+1], L_tmp4);
205             L_tmp3 = fxp_mac_16by16(tmp2, fir_6k_7k[j+2], L_tmp3);
206
207             tmp1 = x[(i<<2)+j+5];
208             tmp2 = x[(i<<2)+j+6];
209
210             L_tmp4 = fxp_mac_16by16(tmp1, fir_6k_7k[j+2], L_tmp4);
211             L_tmp3 = fxp_mac_16by16(tmp1, fir_6k_7k[j+3], L_tmp3);
212             L_tmp4 = fxp_mac_16by16(tmp2, fir_6k_7k[j+3], L_tmp4);
213
214         }
215
216         L_tmp1 = fxp_mac_16by16(x[(i<<2)+j  ], fir_6k_7k[L_FIR-1  ], L_tmp1);
217         L_tmp2 = fxp_mac_16by16(x[(i<<2)+j+1], fir_6k_7k[L_FIR-1  ], L_tmp2);
218         L_tmp3 = fxp_mac_16by16(x[(i<<2)+j+2], fir_6k_7k[L_FIR-1  ], L_tmp3);
219         L_tmp4 = fxp_mac_16by16(x[(i<<2)+j+3], fir_6k_7k[L_FIR-1  ], L_tmp4);
220
221
222         *(pt_sign++) = (int16)(L_tmp1 >> 15);
223         *(pt_sign++) = (int16)(L_tmp2 >> 15);
224         *(pt_sign++) = (int16)(L_tmp3 >> 15);
225         *(pt_sign++) = (int16)(L_tmp4 >> 15);
226
227     }
228
229     pv_memcpy((void *)mem, (void *)(x + lg), L_FIR*sizeof(*mem));
230
231 }
232