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: d2_11pf.cpp
35
36 ------------------------------------------------------------------------------
37 MODULE DESCRIPTION
38 */
39
40 /*----------------------------------------------------------------------------
41 ; INCLUDES
42 ----------------------------------------------------------------------------*/
43 #include "d2_11pf.h"
44 #include "typedef.h"
45 #include "cnst.h"
46
47
48 /*----------------------------------------------------------------------------
49 ; MACROS
50 ; Define module specific macros here
51 ----------------------------------------------------------------------------*/
52
53 /*----------------------------------------------------------------------------
54 ; DEFINES
55 ; Include all pre-processor statements here. Include conditional
56 ; compile variables also.
57 ----------------------------------------------------------------------------*/
58 #define NB_PULSE 2
59
60
61 /*----------------------------------------------------------------------------
62 ; LOCAL FUNCTION DEFINITIONS
63 ; Function Prototype declaration
64 ----------------------------------------------------------------------------*/
65
66 /*----------------------------------------------------------------------------
67 ; LOCAL VARIABLE DEFINITIONS
68 ; Variable declaration - defined here and used outside this module
69 ----------------------------------------------------------------------------*/
70
71 /*
72 ------------------------------------------------------------------------------
73 FUNCTION NAME: decode_2i40_11bits
74 ------------------------------------------------------------------------------
75 INPUT AND OUTPUT DEFINITIONS
76
77 Inputs:
78 sign -- Word16 -- signs of 2 pulses.
79 index -- Word16 -- Positions of the 2 pulses.
80
81 Outputs:
82 cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
83
84 Returns:
85 None
86
87 Global Variables Used:
88 None
89
90 Local Variables Needed:
91 None
92
93 ------------------------------------------------------------------------------
94 FUNCTION DESCRIPTION
95
96
97 ------------------------------------------------------------------------------
98 REQUIREMENTS
99
100 None
101
102 ------------------------------------------------------------------------------
103 REFERENCES
104
105 d2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
106
107 ------------------------------------------------------------------------------
108 PSEUDO-CODE
109
110
111 ------------------------------------------------------------------------------
112 CAUTION [optional]
113 [State any special notes, constraints or cautions for users of this function]
114
115 ------------------------------------------------------------------------------
116 */
117
decode_2i40_11bits(Word16 sign,Word16 index,Word16 cod[])118 void decode_2i40_11bits(
119 Word16 sign, /* i : signs of 2 pulses. */
120 Word16 index, /* i : Positions of the 2 pulses. */
121 Word16 cod[] /* o : algebraic (fixed) codebook excitation */
122 )
123
124 {
125 Word16 i;
126 Word16 j;
127
128 Word16 pos[NB_PULSE];
129
130 /* Decode the positions */
131
132 j = index & 0x1;
133
134 index >>= 1;
135
136 i = index & 0x7;
137
138 pos[0] = i * 5 + j * 2 + 1;
139
140
141
142
143 index >>= 3;
144
145 j = index & 0x3;
146
147 index >>= 2;
148
149 i = index & 0x7;
150
151 if (j == 3)
152 {
153 pos[1] = i * 5 + 4;
154 }
155 else
156 {
157 pos[1] = i * 5 + j;
158 }
159
160
161
162
163 /* decode the signs and build the codeword */
164 for (i = 0; i < L_SUBFR; i++)
165 {
166 cod[i] = 0;
167 }
168
169 for (j = 0; j < NB_PULSE; j++)
170 {
171 i = sign & 1;
172
173 /* This line is equivalent to...
174 *
175 *
176 * if (i == 1)
177 * {
178 * cod[pos[j]] = 8191;
179 * }
180 * if (i == 0)
181 * {
182 * cod[pos[j]] = -8192;
183 * }
184 */
185
186 cod[pos[j]] = i * 16383 - 8192;
187
188 sign >>= 1;
189 }
190
191 return;
192 }
193