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 ------------------------------------------------------------------------------
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------
49 ; Define module specific macros here
50 ----------------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------------
54 ; Include all pre-processor statements here. Include conditional
55 ; compile variables also.
56 ----------------------------------------------------------------------------*/
57 #define NB_PULSE 10 /* number of pulses */
59 /*----------------------------------------------------------------------------
60 ; LOCAL FUNCTION DEFINITIONS
61 ; Function Prototype declaration
62 ----------------------------------------------------------------------------*/
64 /*----------------------------------------------------------------------------
65 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
66 ; Variable declaration - defined here and used outside this module
67 ----------------------------------------------------------------------------*/
70 ------------------------------------------------------------------------------
71 FUNCTION NAME: dec_10i40_35bits
72 ------------------------------------------------------------------------------
73 INPUT AND OUTPUT DEFINITIONS
76 index = buffer containing index of 10 pulses; each element is
77 represented by sign+position
78 cod = buffer of algebraic (fixed) codebook excitation
81 cod buffer contains the new algebraic codebook excitation
86 Global Variables Used:
87 dgray = gray decoding table
89 Local Variables Needed:
92 ------------------------------------------------------------------------------
95 This function builds the innovative codevector from the received index of
96 algebraic codebook. See c1035pf.c for more details about the algebraic
99 ------------------------------------------------------------------------------
104 ------------------------------------------------------------------------------
107 d1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
109 ------------------------------------------------------------------------------
112 void dec_10i40_35bits (
113 Word16 index[], // (i) : index of 10 pulses (sign+position)
114 Word16 cod[] // (o) : algebraic (fixed) codebook excitation
117 Word16 i, j, pos1, pos2, sign, tmp;
119 for (i = 0; i < L_CODE; i++)
124 // decode the positions and signs of pulses and build the codeword
126 for (j = 0; j < NB_TRACK; j++)
134 i = extract_l (L_shr (L_mult (i, 5), 1));
135 pos1 = add (i, j); // position of pulse "j"
137 i = shr (tmp, 3) & 1;
144 sign = -4096; // -1.0
151 i = index[add (j, 5)] & 7;
153 i = extract_l (L_shr (L_mult (i, 5), 1));
155 pos2 = add (i, j); // position of pulse "j+5"
157 if (sub (pos2, pos1) < 0)
159 sign = negate (sign);
161 cod[pos2] = add (cod[pos2], sign);
167 ------------------------------------------------------------------------------
169 [State any special notes, constraints or cautions for users of this function]
171 ------------------------------------------------------------------------------
174 void dec_10i40_35bits(
175 Word16 index[], /* (i) : index of 10 pulses (sign+position) */
176 Word16 cod[], /* (o) : algebraic (fixed) codebook excitation */
177 const Word16* dgray_ptr /* i : ptr to read-only tbl */
180 register Word16 i, j, pos1, pos2;
183 for (i = 0; i < L_CODE; i++)
188 /* decode the positions and signs of pulses and build the codeword */
190 for (j = 0; j < NB_TRACK; j++)
192 /* compute index i */
196 i = *(dgray_ptr + i);
199 pos1 = i + j; /* position of pulse "j" */
205 sign = 4096; /* +1.0 */
209 sign = -4096; /* -1.0 */
212 *(cod + pos1) = sign;
214 /* compute index i */
216 i = *(index + j + 5) & 7;
217 i = *(dgray_ptr + i);
220 pos2 = i + j; /* position of pulse "j+5" */
227 *(cod + pos2) += sign;