Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / isp_isf.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: isp_isf.cpp
35
36 ------------------------------------------------------------------------------
37  INPUT AND OUTPUT DEFINITIONS
38
39      int16 isf[],       (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5)
40      int16 isp[],       (o) Q15 : isp[m] (range: -1<=val<1)
41      int16 m            (i)     : LPC order
42
43
44 ------------------------------------------------------------------------------
45  FUNCTION DESCRIPTION
46
47      Isf_isp   Transformation isf to isp
48
49    The transformation from isf[i] to isp[i] is
50    approximated by a look-up table and interpolation.
51
52
53
54 ------------------------------------------------------------------------------
55  REQUIREMENTS
56
57
58 ------------------------------------------------------------------------------
59  REFERENCES
60
61 ------------------------------------------------------------------------------
62  PSEUDO-CODE
63
64 ------------------------------------------------------------------------------
65 */
66
67
68 /*----------------------------------------------------------------------------
69 ; INCLUDES
70 ----------------------------------------------------------------------------*/
71
72
73 #include "pv_amr_wb_type_defs.h"
74 #include "pvamrwbdecoder_basic_op.h"
75 #include "pvamrwbdecoder_acelp.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 /*----------------------------------------------------------------------------
90 ; LOCAL FUNCTION DEFINITIONS
91 ; Function Prototype declaration
92 ----------------------------------------------------------------------------*/
93
94 /*----------------------------------------------------------------------------
95 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
96 ; Variable declaration - defined here and used outside this module
97 ----------------------------------------------------------------------------*/
98
99 /* Look-up table for transformations */
100
101 /* table of cos(x) in Q15 */
102
103 static const int16 table[129] =
104 {
105     32767,
106     32758,  32729,  32679,  32610,  32522,  32413,  32286,  32138,
107     31972,  31786,  31581,  31357,  31114,  30853,  30572,  30274,
108     29957,  29622,  29269,  28899,  28511,  28106,  27684,  27246,
109     26791,  26320,  25833,  25330,  24812,  24279,  23732,  23170,
110     22595,  22006,  21403,  20788,  20160,  19520,  18868,  18205,
111     17531,  16846,  16151,  15447,  14733,  14010,  13279,  12540,
112     11793,  11039,  10279,   9512,   8740,   7962,   7180,   6393,
113     5602,   4808,   4011,   3212,   2411,   1608,    804,      0,
114     -804,  -1608,  -2411,  -3212,  -4011,  -4808,  -5602,  -6393,
115     -7180,  -7962,  -8740,  -9512, -10279, -11039, -11793, -12540,
116     -13279, -14010, -14733, -15447, -16151, -16846, -17531, -18205,
117     -18868, -19520, -20160, -20788, -21403, -22006, -22595, -23170,
118     -23732, -24279, -24812, -25330, -25833, -26320, -26791, -27246,
119     -27684, -28106, -28511, -28899, -29269, -29622, -29957, -30274,
120     -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138,
121     -32286, -32413, -32522, -32610, -32679, -32729, -32758, -32768
122 };
123
124
125 /*----------------------------------------------------------------------------
126 ; EXTERNAL FUNCTION REFERENCES
127 ; Declare functions defined elsewhere and referenced in this module
128 ----------------------------------------------------------------------------*/
129
130 /*----------------------------------------------------------------------------
131 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
132 ; Declare variables used in this module but defined elsewhere
133 ----------------------------------------------------------------------------*/
134
135 /*----------------------------------------------------------------------------
136 ; FUNCTION CODE
137 ----------------------------------------------------------------------------*/
138
139
140 void Isf_isp(
141     int16 isf[],     /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
142     int16 isp[],     /* (o) Q15 : isp[m] (range: -1<=val<1)                */
143     int16 m          /* (i)     : LPC order                                */
144 )
145 {
146     int16 i, ind, offset;
147     int32 L_tmp;
148
149     for (i = 0; i < m - 1; i++)
150     {
151         isp[i] = isf[i];
152     }
153     isp[m - 1] = shl_int16(isf[m - 1], 1);
154
155     for (i = 0; i < m; i++)
156     {
157         ind = isp[i] >> 7;            /* ind    = b7-b15 of isf[i] */
158         offset = (isp[i] & 0x007f);       /* offset = b0-b6  of isf[i] */
159
160         /* isp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 128 */
161
162         L_tmp = mul_16by16_to_int32(table[ind + 1] - table[ind], offset);
163         isp[i] = add_int16(table[ind], (int16)(L_tmp >> 8));
164     }
165
166     return;
167 }