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_4i40_17bits
37 ------------------------------------------------------------------------------
41 FUNCTION: decode_4i40_17bits (decod_ACELP())
43 PURPOSE: Algebraic codebook decoder. For details about the encoding see
47 /*----------------------------------------------------------------------------
49 ----------------------------------------------------------------------------*/
55 /*--------------------------------------------------------------------------*/
61 /*----------------------------------------------------------------------------
63 ; Define module specific macros here
64 ----------------------------------------------------------------------------*/
66 /*----------------------------------------------------------------------------
68 ; Include all pre-processor statements here. Include conditional
69 ; compile variables also.
70 ----------------------------------------------------------------------------*/
71 #define NB_PULSE 4 /* number of pulses */
74 /*----------------------------------------------------------------------------
75 ; LOCAL FUNCTION DEFINITIONS
76 ; Function Prototype declaration
77 ----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------
80 ; LOCAL VARIABLE DEFINITIONS
81 ; Variable declaration - defined here and used outside this module
82 ----------------------------------------------------------------------------*/
84 /*----------------------------------------------------------------------------
85 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
86 ; Declare variables used in this module but defined elsewhere
87 ----------------------------------------------------------------------------*/
89 /*--------------------------------------------------------------------------*/
95 ------------------------------------------------------------------------------
96 FUNCTION NAME: decode_4i40_17bits
97 ------------------------------------------------------------------------------
98 INPUT AND OUTPUT DEFINITIONS
101 sign -- Word16 -- signs of 3 pulses.
102 index -- Word16 -- Positions of the 3 pulses.
105 cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
110 Global Variables Used:
113 Local Variables Needed:
116 ------------------------------------------------------------------------------
120 ------------------------------------------------------------------------------
125 ------------------------------------------------------------------------------
128 d4_17pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
130 ------------------------------------------------------------------------------
134 ------------------------------------------------------------------------------
136 [State any special notes, constraints or cautions for users of this function]
138 ------------------------------------------------------------------------------
141 void decode_4i40_17bits(
142 Word16 sign, /* i : signs of 4 pulses. */
143 Word16 index, /* i : Positions of the 4 pulses. */
144 const Word16* dgray_ptr, /* i : Pointer to read-only table */
145 Word16 cod[] /* o : algebraic (fixed) codebook excitation */
151 Word16 pos[NB_PULSE];
153 /* Index is a 13-bit value. 3 bits each correspond to the
154 * positions 0-2, with 4 bits allocated for position 3.
157 * [][][][] [][][] [][][] [][][]
160 * pos3 pos2 pos1 pos0
163 /* Decode the positions */
169 pos[0] = i * 5; /* pos0 =i*5 */
178 pos[1] = i * 5 + 1; /* pos1 =i*5+1 */
188 pos[2] = i * 5 + 2; /* pos2 =i*5+2 */
204 pos[3] = i * 5 + 3 + j; /* pos3 =i*5+3+j */
207 /* decode the signs and build the codeword */
209 for (i = 0; i < L_SUBFR; i++)
214 for (j = 0; j < NB_PULSE; j++)
218 /* This line is equivalent to...
223 * cod[pos[j]] = 8191;
227 * cod[pos[j]] = -8192;
231 cod[pos[j]] = i * 16383 - 8192;