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