1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
35 Functions: decode_2i40_9bits
37 ------------------------------------------------------------------------------
41 FUNCTION: decode_2i40_9bits (decod_ACELP())
43 PURPOSE: Algebraic codebook decoder. For details about the encoding see
47 /*----------------------------------------------------------------------------
49 ----------------------------------------------------------------------------*/
56 /*--------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------
64 ; Define module specific macros here
65 ----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------
69 ; Include all pre-processor statements here. Include conditional
70 ; compile variables also.
71 ----------------------------------------------------------------------------*/
75 /*----------------------------------------------------------------------------
76 ; LOCAL FUNCTION DEFINITIONS
77 ; Function Prototype declaration
78 ----------------------------------------------------------------------------*/
80 /*----------------------------------------------------------------------------
81 ; LOCAL VARIABLE DEFINITIONS
82 ; Variable declaration - defined here and used outside this module
83 ----------------------------------------------------------------------------*/
85 /*--------------------------------------------------------------------------*/
91 ------------------------------------------------------------------------------
92 FUNCTION NAME: decode_2i40_11bits
93 ------------------------------------------------------------------------------
94 INPUT AND OUTPUT DEFINITIONS
97 sign -- Word16 -- signs of 2 pulses.
98 index -- Word16 -- Positions of the 2 pulses.
101 cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
102 pOverflow = pointer to overflow flag
107 Global Variables Used:
110 Local Variables Needed:
113 ------------------------------------------------------------------------------
117 ------------------------------------------------------------------------------
122 ------------------------------------------------------------------------------
125 d2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
127 ------------------------------------------------------------------------------
131 ------------------------------------------------------------------------------
133 [State any special notes, constraints or cautions for users of this function]
135 ------------------------------------------------------------------------------
138 void decode_2i40_9bits(
139 Word16 subNr, /* i : subframe number */
140 Word16 sign, /* i : signs of 2 pulses. */
141 Word16 index, /* i : Positions of the 2 pulses. */
142 const Word16* startPos_ptr, /* i: ptr to read only table */
143 Word16 cod[], /* o : algebraic (fixed) codebook excitation */
144 Flag *pOverflow /* o : Flag set when overflow occurs */
151 Word16 pos[NB_PULSE];
153 /* Decode the positions */
154 /* table bit is the MSB */
156 j = (Word16)(index & 64);
170 /* pos0 =i*5+startPos_ptr[j*8+subNr*2] */
171 pos[0] = i * 5 + startPos_ptr[k++];
178 /* pos1 =i*5+startPos_ptr[j*8+subNr*2 + 1] */
179 pos[1] = i * 5 + startPos_ptr[k];
182 /* decode the signs and build the codeword */
184 for (i = L_SUBFR - 1; i >= 0; i--)
189 for (j = 0; j < NB_PULSE; j++)
193 /* This line is equivalent to...
198 * cod[pos[j]] = 8191;
202 * cod[pos[j]] = -8192;
206 cod[pos[j]] = i * 16383 - 8192;