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 ------------------------------------------------------------------------------
34 Pathname: ./audio/gsm-amr/c/src/d8_31pf.c
40 ------------------------------------------------------------------------------
43 Description: Modified to pass overflow flag through to basic math function.
44 The flag is passed back to the calling function by pointer reference.
46 Description: Per review comments...
47 (1) Removed include of "count.h" and "basic_op.h"
48 (2) Added includes of mult.h, shl.h, shr.h, add.h, sub.h, negate.h,
51 Description: Replaced "int" and/or "char" with OSCL defined types.
55 ------------------------------------------------------------------------------
59 /*----------------------------------------------------------------------------
61 ----------------------------------------------------------------------------*/
68 /*----------------------------------------------------------------------------
70 ; Define module specific macros here
71 ----------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------
75 ; Include all pre-processor statements here. Include conditional
76 ; compile variables also.
77 ----------------------------------------------------------------------------*/
78 #define NB_PULSE 8 /* number of pulses */
80 /* define values/representation for output codevector and sign */
85 /*----------------------------------------------------------------------------
86 ; LOCAL FUNCTION DEFINITIONS
87 ; Function Prototype declaration
88 ----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------
91 ; LOCAL VARIABLE DEFINITIONS
92 ; Variable declaration - defined here and used outside this module
93 ----------------------------------------------------------------------------*/
96 ------------------------------------------------------------------------------
97 FUNCTION NAME: decompress10
98 ------------------------------------------------------------------------------
99 INPUT AND OUTPUT DEFINITIONS
102 MSBs -- Word16 -- MSB part of the index
103 LSBs -- Word16 -- LSB part of the index
104 index1 -- Word16 -- index for first pos in pos_index[]
105 index2 -- Word16 -- index for second pos in pos_index[]
106 index3 -- Word16 -- index for third pos in pos_index[]
109 pos_indx[] -- array of type Word16 -- position of 3 pulses (decompressed)
111 pOverflow Flag set when overflow occurs, pointer of type Flag *
116 Global Variables Used:
119 Local Variables Needed:
122 ------------------------------------------------------------------------------
126 ------------------------------------------------------------------------------
131 ------------------------------------------------------------------------------
134 d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
136 ------------------------------------------------------------------------------
140 ------------------------------------------------------------------------------
141 RESOURCES USED [optional]
143 When the code is written for a specific target processor the
144 the resources used should be documented below.
146 HEAP MEMORY USED: x bytes
148 STACK MEMORY USED: x bytes
150 CLOCK CYCLES: (cycle count equation for this function) + (variable
151 used to represent cycle count for each subroutine
153 where: (cycle count variable) = cycle count for [subroutine
156 ------------------------------------------------------------------------------
158 [State any special notes, constraints or cautions for users of this function]
160 ------------------------------------------------------------------------------
163 static void decompress10(
164 Word16 MSBs, /* i : MSB part of the index */
165 Word16 LSBs, /* i : LSB part of the index */
166 Word16 index1, /* i : index for first pos in pos_index[] */
167 Word16 index2, /* i : index for second pos in pos_index[] */
168 Word16 index3, /* i : index for third pos in pos_index[] */
169 Word16 pos_indx[], /* o : position of 3 pulses (decompressed) */
170 Flag *pOverflow) /* o : Flag set when overflow occurs */
178 pos_indx[index1] = ((MSBs-25*(MSBs/25))%5)*2 + (LSBs-4*(LSBs/4))%2;
179 pos_indx[index2] = ((MSBs-25*(MSBs/25))/5)*2 + (LSBs-4*(LSBs/4))/2;
180 pos_indx[index3] = (MSBs/25)*2 + LSBs/4;
201 ia = (Word16)(MSBs - (tempWord32 >> 1));
214 ib = ia - (Word16)(tempWord32 >> 1);
223 ic = LSBs - ((LSBs >> 2) << 2);
226 pos_indx[index1] = ib + (ic & 1);
242 pos_indx[index2] = ib + (ic >> 1);
270 ------------------------------------------------------------------------------
271 FUNCTION NAME: decompress_code
272 ------------------------------------------------------------------------------
273 INPUT AND OUTPUT DEFINITIONS
276 indx[] -- array of type Word16 -- position and sign of
277 8 pulses (compressed)
280 sign_indx[] -- array of type Word16 -- signs of 4 pulses (signs only)
281 pos_indx[] -- array of type Word16 -- position index of 8 pulses
283 pOverflow pointer to type Flag -- Flag set when overflow occurs
288 Global Variables Used:
291 Local Variables Needed:
294 ------------------------------------------------------------------------------
297 PURPOSE: decompression of the linear codewords to 4+three indeces
298 one bit from each pulse is made robust to errors by
299 minimizing the phase shift of a bit error.
300 4 signs (one for each track)
301 i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust
302 i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust
303 i3,i7 => one index (5+2) bits, 2-3 LSbs more robust
305 ------------------------------------------------------------------------------
310 ------------------------------------------------------------------------------
313 d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
315 ------------------------------------------------------------------------------
319 ------------------------------------------------------------------------------
320 RESOURCES USED [optional]
322 When the code is written for a specific target processor the
323 the resources used should be documented below.
325 HEAP MEMORY USED: x bytes
327 STACK MEMORY USED: x bytes
329 CLOCK CYCLES: (cycle count equation for this function) + (variable
330 used to represent cycle count for each subroutine
332 where: (cycle count variable) = cycle count for [subroutine
335 ------------------------------------------------------------------------------
337 [State any special notes, constraints or cautions for users of this function]
339 ------------------------------------------------------------------------------
342 static void decompress_code(
343 Word16 indx[], /* i : position and sign of 8 pulses (compressed) */
344 Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */
345 Word16 pos_indx[], /* o : position index of 8 pulses (position only) */
346 Flag *pOverflow /* o : Flag set when overflow occurs */
357 for (i = 0; i < NB_TRACK_MR102; i++)
359 sign_indx[i] = indx[i];
363 First index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
364 MSBs = indx[NB_TRACK]/8;
365 LSBs = indx[NB_TRACK]%8;
367 MSBs = indx[NB_TRACK_MR102] >> 3;
369 LSBs = indx[NB_TRACK_MR102] & 0x7;
381 Second index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
382 MSBs = indx[NB_TRACK+1]/8;
383 LSBs = indx[NB_TRACK+1]%8;
385 MSBs = indx[NB_TRACK_MR102+1] >> 3;
387 LSBs = indx[NB_TRACK_MR102+1] & 0x7;
399 Third index: 10x10 -> 2x5x2x5-> 25x2x2 -> 5+1x2 bits
400 MSBs = indx[NB_TRACK+2]/4;
401 LSBs = indx[NB_TRACK+2]%4;
402 MSBs0_24 = (MSBs*25+12)/32;
403 if ((MSBs0_24/5)%2==1)
404 pos_indx[3] = (4-(MSBs0_24%5))*2 + LSBs%2;
406 pos_indx[3] = (MSBs0_24%5)*2 + LSBs%2;
407 pos_indx[7] = (MSBs0_24/5)*2 + LSBs/2;
410 MSBs = indx[NB_TRACK_MR102+2] >> 2;
412 LSBs = indx[NB_TRACK_MR102+2] & 0x3;
454 ib = MSBs0_24 - (Word16)(tempWord32 >> 1);
489 pos_indx[7] = ia + (LSBs >> 1);
494 ------------------------------------------------------------------------------
495 FUNCTION NAME: dec_8i40_31bits
496 ------------------------------------------------------------------------------
497 INPUT AND OUTPUT DEFINITIONS
500 index array of type Word16 -- index of 8 pulses (sign+position)
503 cod array of type Word16 -- algebraic (fixed) codebook excitation
504 pOverflow pointer to type Flag -- Flag set when overflow occurs
509 Global Variables Used:
512 Local Variables Needed:
515 ------------------------------------------------------------------------------
518 PURPOSE: Builds the innovative codevector from the received
519 index of algebraic codebook.
521 ------------------------------------------------------------------------------
526 ------------------------------------------------------------------------------
529 d8_31pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
531 ------------------------------------------------------------------------------
535 ------------------------------------------------------------------------------
536 RESOURCES USED [optional]
538 When the code is written for a specific target processor the
539 the resources used should be documented below.
541 HEAP MEMORY USED: x bytes
543 STACK MEMORY USED: x bytes
545 CLOCK CYCLES: (cycle count equation for this function) + (variable
546 used to represent cycle count for each subroutine
548 where: (cycle count variable) = cycle count for [subroutine
551 ------------------------------------------------------------------------------
553 [State any special notes, constraints or cautions for users of this function]
555 ------------------------------------------------------------------------------
558 void dec_8i40_31bits(
559 Word16 index[], /* i : index of 8 pulses (sign+position) */
560 Word16 cod[], /* o : algebraic (fixed) codebook excitation */
561 Flag *pOverflow /* o : Flag set when overflow occurs */
570 Word16 linear_signs[NB_TRACK_MR102];
571 Word16 linear_codewords[NB_PULSE];
573 for (i = 0; i < L_CODE; i++)
584 /* decode the positions and signs of pulses and build the codeword */
585 for (j = 0; j < NB_TRACK_MR102; j++) /* NB_TRACK_MR102 = 4 */
587 /* position of pulse "j" */
589 pos1 = (linear_codewords[j] << 2) + j;
592 if (linear_signs[j] == 0)
594 sign = POS_CODE; /* +1.0 */
598 sign = -NEG_CODE; /* -1.0 */
603 cod[pos1] = sign; /* avoid buffer overflow */
606 /* compute index i */
607 /* position of pulse "j+4" */
609 pos2 = (linear_codewords[j + 4] << 2) + j;
619 cod[pos2] += sign; /* avoid buffer overflow */
623 } /* for (j = 0; j < NB_TRACK_MR102; j++) */