Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / inter_36.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.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2004, 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: inter_36.cpp
35
36 ------------------------------------------------------------------------------
37 */
38
39 /*----------------------------------------------------------------------------
40 ; INCLUDES
41 ----------------------------------------------------------------------------*/
42 #include "inter_36.h"
43 #include "cnst.h"
44 #include "inter_36_tab.h"
45 #include "basic_op.h"
46
47 /*----------------------------------------------------------------------------
48 ; MACROS
49 ; Define module specific macros here
50 ----------------------------------------------------------------------------*/
51
52
53 /*----------------------------------------------------------------------------
54 ; DEFINES
55 ; Include all pre-processor statements here. Include conditional
56 ; compile variables also.
57 ----------------------------------------------------------------------------*/
58 #define UP_SAMP_MAX  6
59
60 /*----------------------------------------------------------------------------
61 ; LOCAL FUNCTION DEFINITIONS
62 ; Function Prototype declaration
63 ----------------------------------------------------------------------------*/
64
65
66 /*----------------------------------------------------------------------------
67 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
68 ; Variable declaration - defined here and used outside this module
69 ----------------------------------------------------------------------------*/
70
71
72 /*
73 ------------------------------------------------------------------------------
74  FUNCTION NAME: inter_36
75 ------------------------------------------------------------------------------
76  INPUT AND OUTPUT DEFINITIONS
77
78  Inputs:
79     pX    = pointer to input vector of type Word16
80     frac  = fraction  (-2..2 for 3*, -3..3 for 6*)  of type Word16
81     flag3 = if set, upsampling rate = 3 (6 otherwise) of type Word16
82     pOverflow = pointer to overflow flag
83
84  Outputs:
85     None
86
87  Returns:
88     None
89
90  Global Variables Used:
91     None.
92
93  Local Variables Needed:
94     None.
95
96 ------------------------------------------------------------------------------
97  FUNCTION DESCRIPTION
98
99       File             : inter_36.c
100       Purpose          : Interpolating the normalized correlation
101                        : with 1/3 or 1/6 resolution.
102
103 ------------------------------------------------------------------------------
104  REQUIREMENTS
105
106  None.
107
108 ------------------------------------------------------------------------------
109  REFERENCES
110
111  inter_36.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
112
113 ------------------------------------------------------------------------------
114  PSEUDO-CODE
115
116     Word16 i, k;
117     Word16 *x1, *x2;
118     const Word16 *c1, *c2;
119     Word32 s;
120
121     if (flag3 != 0)
122     {
123       frac = shl (frac, 1);   // inter_3[k] = inter_6[2*k] -> k' = 2*k
124     }
125
126     if (frac < 0)
127     {
128         frac = add (frac, UP_SAMP_MAX);
129         x--;
130     }
131
132     x1 = &x[0];
133     x2 = &x[1];
134     c1 = &inter_6[frac];
135     c2 = &inter_6[sub (UP_SAMP_MAX, frac)];
136
137     s = 0;
138     for (i = 0, k = 0; i < L_INTER_SRCH; i++, k += UP_SAMP_MAX)
139     {
140         s = L_mac (s, x1[-i], c1[k]);
141         s = L_mac (s, x2[i], c2[k]);
142     }
143
144     return pv_round (s);
145
146 ------------------------------------------------------------------------------
147  CAUTION [optional]
148  [State any special notes, constraints or cautions for users of this function]
149
150 ------------------------------------------------------------------------------
151 */
152 Word16 Interpol_3or6(   /* o : interpolated value                        */
153     Word16 *pX,         /* i : input vector                              */
154     Word16 frac,        /* i : fraction  (-2..2 for 3*, -3..3 for 6*)    */
155     Word16 flag3,       /* i : if set, upsampling rate = 3 (6 otherwise) */
156     Flag   *pOverflow
157 )
158 {
159     Word16 i;
160     Word16 k;
161     Word16 *pX1;
162     Word16 *pX2;
163     const Word16 *pC1;
164     const Word16 *pC2;
165     Word32 s;
166     Word16 temp1;
167
168     OSCL_UNUSED_ARG(pOverflow);
169
170     if (flag3 != 0)
171     {
172         frac <<= 1;
173         /* inter_3[k] = inter_6[2*k] -> k' = 2*k */
174     }
175
176     if (frac < 0)
177     {
178         frac += UP_SAMP_MAX;
179         pX--;
180     }
181
182     pX1   = &pX[0];
183     pX2   = &pX[1];
184     pC1   = &inter_6[frac];
185     temp1 = UP_SAMP_MAX - frac;
186     pC2   = &inter_6[temp1];
187
188     s = 0x04000;
189     k = 0;
190
191     for (i = (L_INTER_SRCH >> 1); i != 0; i--)
192     {
193         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX1--), (Word32) pC1[k], s);
194         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX2++), (Word32) pC2[k], s);
195         k += UP_SAMP_MAX;
196         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX1--), (Word32) pC1[k], s);
197         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX2++), (Word32) pC2[k], s);
198         k <<= 1;
199     }
200
201     return((Word16)(s >> 15));
202 }
203
204
205
206
207
208