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 ------------------------------------------------------------------------------
41 /*----------------------------------------------------------------------------
43 ----------------------------------------------------------------------------*/
50 /*----------------------------------------------------------------------------
52 ; Define module specific macros here
53 ----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------
57 ; Include all pre-processor statements here. Include conditional
58 ; compile variables also.
59 ----------------------------------------------------------------------------*/
60 #define NB_PULSE 8 /* number of pulses */
62 /* define values/representation for output codevector and sign */
67 /*----------------------------------------------------------------------------
68 ; LOCAL FUNCTION DEFINITIONS
69 ; Function Prototype declaration
70 ----------------------------------------------------------------------------*/
72 /*----------------------------------------------------------------------------
73 ; LOCAL VARIABLE DEFINITIONS
74 ; Variable declaration - defined here and used outside this module
75 ----------------------------------------------------------------------------*/
78 ------------------------------------------------------------------------------
79 FUNCTION NAME: decompress10
80 ------------------------------------------------------------------------------
81 INPUT AND OUTPUT DEFINITIONS
84 MSBs -- Word16 -- MSB part of the index
85 LSBs -- Word16 -- LSB part of the index
86 index1 -- Word16 -- index for first pos in pos_index[]
87 index2 -- Word16 -- index for second pos in pos_index[]
88 index3 -- Word16 -- index for third pos in pos_index[]
91 pos_indx[] -- array of type Word16 -- position of 3 pulses (decompressed)
93 pOverflow Flag set when overflow occurs, pointer of type Flag *
98 Global Variables Used:
101 Local Variables Needed:
104 ------------------------------------------------------------------------------
108 ------------------------------------------------------------------------------
113 ------------------------------------------------------------------------------
116 d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
118 ------------------------------------------------------------------------------
122 ------------------------------------------------------------------------------
124 [State any special notes, constraints or cautions for users of this function]
126 ------------------------------------------------------------------------------
129 static void decompress10(
130 Word16 MSBs, /* i : MSB part of the index */
131 Word16 LSBs, /* i : LSB part of the index */
132 Word16 index1, /* i : index for first pos in pos_index[] */
133 Word16 index2, /* i : index for second pos in pos_index[] */
134 Word16 index3, /* i : index for third pos in pos_index[] */
135 Word16 pos_indx[], /* o : position of 3 pulses (decompressed) */
136 Flag *pOverflow) /* o : Flag set when overflow occurs */
144 pos_indx[index1] = ((MSBs-25*(MSBs/25))%5)*2 + (LSBs-4*(LSBs/4))%2;
145 pos_indx[index2] = ((MSBs-25*(MSBs/25))/5)*2 + (LSBs-4*(LSBs/4))/2;
146 pos_indx[index3] = (MSBs/25)*2 + LSBs/4;
167 ia = (Word16)(MSBs - (tempWord32 >> 1));
180 ib = ia - (Word16)(tempWord32 >> 1);
189 ic = LSBs - ((LSBs >> 2) << 2);
192 pos_indx[index1] = ib + (ic & 1);
208 pos_indx[index2] = ib + (ic >> 1);
225 pos_indx[index3] = add_16(ib, ic, pOverflow);
232 ------------------------------------------------------------------------------
233 FUNCTION NAME: decompress_code
234 ------------------------------------------------------------------------------
235 INPUT AND OUTPUT DEFINITIONS
238 indx[] -- array of type Word16 -- position and sign of
239 8 pulses (compressed)
242 sign_indx[] -- array of type Word16 -- signs of 4 pulses (signs only)
243 pos_indx[] -- array of type Word16 -- position index of 8 pulses
245 pOverflow pointer to type Flag -- Flag set when overflow occurs
250 Global Variables Used:
253 Local Variables Needed:
256 ------------------------------------------------------------------------------
259 PURPOSE: decompression of the linear codewords to 4+three indeces
260 one bit from each pulse is made robust to errors by
261 minimizing the phase shift of a bit error.
262 4 signs (one for each track)
263 i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust
264 i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust
265 i3,i7 => one index (5+2) bits, 2-3 LSbs more robust
267 ------------------------------------------------------------------------------
272 ------------------------------------------------------------------------------
275 d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
277 ------------------------------------------------------------------------------
281 ------------------------------------------------------------------------------
283 [State any special notes, constraints or cautions for users of this function]
285 ------------------------------------------------------------------------------
288 static void decompress_code(
289 Word16 indx[], /* i : position and sign of 8 pulses (compressed) */
290 Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */
291 Word16 pos_indx[], /* o : position index of 8 pulses (position only) */
292 Flag *pOverflow /* o : Flag set when overflow occurs */
303 for (i = 0; i < NB_TRACK_MR102; i++)
305 sign_indx[i] = indx[i];
309 First index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
310 MSBs = indx[NB_TRACK]/8;
311 LSBs = indx[NB_TRACK]%8;
313 MSBs = indx[NB_TRACK_MR102] >> 3;
315 LSBs = indx[NB_TRACK_MR102] & 0x7;
327 Second index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
328 MSBs = indx[NB_TRACK+1]/8;
329 LSBs = indx[NB_TRACK+1]%8;
331 MSBs = indx[NB_TRACK_MR102+1] >> 3;
333 LSBs = indx[NB_TRACK_MR102+1] & 0x7;
345 Third index: 10x10 -> 2x5x2x5-> 25x2x2 -> 5+1x2 bits
346 MSBs = indx[NB_TRACK+2]/4;
347 LSBs = indx[NB_TRACK+2]%4;
348 MSBs0_24 = (MSBs*25+12)/32;
349 if ((MSBs0_24/5)%2==1)
350 pos_indx[3] = (4-(MSBs0_24%5))*2 + LSBs%2;
352 pos_indx[3] = (MSBs0_24%5)*2 + LSBs%2;
353 pos_indx[7] = (MSBs0_24/5)*2 + LSBs/2;
356 MSBs = indx[NB_TRACK_MR102+2] >> 2;
358 LSBs = indx[NB_TRACK_MR102+2] & 0x3;
400 ib = MSBs0_24 - (Word16)(tempWord32 >> 1);
435 pos_indx[7] = ia + (LSBs >> 1);
440 ------------------------------------------------------------------------------
441 FUNCTION NAME: dec_8i40_31bits
442 ------------------------------------------------------------------------------
443 INPUT AND OUTPUT DEFINITIONS
446 index array of type Word16 -- index of 8 pulses (sign+position)
449 cod array of type Word16 -- algebraic (fixed) codebook excitation
450 pOverflow pointer to type Flag -- Flag set when overflow occurs
455 Global Variables Used:
458 Local Variables Needed:
461 ------------------------------------------------------------------------------
464 PURPOSE: Builds the innovative codevector from the received
465 index of algebraic codebook.
467 ------------------------------------------------------------------------------
472 ------------------------------------------------------------------------------
475 d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
477 ------------------------------------------------------------------------------
481 ------------------------------------------------------------------------------
483 [State any special notes, constraints or cautions for users of this function]
485 ------------------------------------------------------------------------------
488 void dec_8i40_31bits(
489 Word16 index[], /* i : index of 8 pulses (sign+position) */
490 Word16 cod[], /* o : algebraic (fixed) codebook excitation */
491 Flag *pOverflow /* o : Flag set when overflow occurs */
500 Word16 linear_signs[NB_TRACK_MR102];
501 Word16 linear_codewords[NB_PULSE];
503 for (i = 0; i < L_CODE; i++)
514 /* decode the positions and signs of pulses and build the codeword */
515 for (j = 0; j < NB_TRACK_MR102; j++) /* NB_TRACK_MR102 = 4 */
517 /* position of pulse "j" */
519 pos1 = (linear_codewords[j] << 2) + j;
522 if (linear_signs[j] == 0)
524 sign = POS_CODE; /* +1.0 */
528 sign = -NEG_CODE; /* -1.0 */
533 cod[pos1] = sign; /* avoid buffer overflow */
536 /* compute index i */
537 /* position of pulse "j+4" */
539 pos2 = (linear_codewords[j + 4] << 2) + j;
549 cod[pos2] += sign; /* avoid buffer overflow */
553 } /* for (j = 0; j < NB_TRACK_MR102; j++) */