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