123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- /*
- ********************************************************************************
- *
- * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
- * R99 Version 3.3.0
- * REL-4 Version 4.1.0
- *
- ********************************************************************************
- *
- * File : d8_31pf.c
- * Purpose : Builds the innovative codevector
- *
- ********************************************************************************
- */
-
- /*
- ********************************************************************************
- * MODULE INCLUDE FILE AND VERSION ID
- ********************************************************************************
- */
- #include "d8_31pf.h"
- const char d8_31pf_id[] = "@(#)$Id $" d8_31pf_h;
-
- /*
- ********************************************************************************
- * INCLUDE FILES
- ********************************************************************************
- */
- #include "typedef.h"
- #include "basic_op.h"
- #include "count.h"
- #include "cnst.h"
- /*
- ********************************************************************************
- * LOCAL VARIABLES AND TABLES
- ********************************************************************************
- */
- #define NB_PULSE 8 /* number of pulses */
- /* define values/representation for output codevector and sign */
- #define POS_CODE 8191
- #define NEG_CODE 8191
- static void decompress10 (
- Word16 MSBs, /* i : MSB part of the index */
- Word16 LSBs, /* i : LSB part of the index */
- Word16 index1, /* i : index for first pos in pos_index[] */
- Word16 index2, /* i : index for second pos in pos_index[] */
- Word16 index3, /* i : index for third pos in pos_index[] */
- Word16 pos_indx[]) /* o : position of 3 pulses (decompressed) */
- {
- Word16 ia, ib, ic;
- /*
- pos_indx[index1] = ((MSBs-25*(MSBs/25))%5)*2 + (LSBs-4*(LSBs/4))%2;
- pos_indx[index2] = ((MSBs-25*(MSBs/25))/5)*2 + (LSBs-4*(LSBs/4))/2;
- pos_indx[index3] = (MSBs/25)*2 + LSBs/4;
- */
- test ();
- if (sub_ex(MSBs, 124) > 0)
- {
- MSBs = 124; move16 ();
- }
-
- ia = mult_ex(MSBs, 1311);
- ia = sub_ex(MSBs, extract_l_ex(L_shr_ex(L_mult_ex(ia, 25), 1)));
- ib = shl_ex(sub_ex(ia, extract_l_ex(L_shr_ex(L_mult_ex(mult_ex(ia, 6554), 5), 1))), 1);
-
- ic = shl_ex(shr_ex(LSBs, 2), 2);
- ic = sub_ex(LSBs, ic);
- pos_indx[index1] = add_ex(ib, (ic & 1)); logic16 ();
-
- ib = shl_ex(mult_ex(ia, 6554), 1);
- pos_indx[index2] = add_ex(ib, shr_ex(ic, 1));
-
- pos_indx[index3] = add_ex(shl_ex(mult_ex(MSBs, 1311), 1), shr_ex(LSBs, 2));
- return;
- }
- /*************************************************************************
- *
- * FUNCTION: decompress_code()
- *
- * PURPOSE: decompression of the linear codewords to 4+three indeces
- * one bit from each pulse is made robust to errors by
- * minimizing the phase shift of a bit error.
- * 4 signs (one for each track)
- * i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust
- * i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust
- * i3,i7 => one index (5+2) bits, 2-3 LSbs more robust
- *
- *************************************************************************/
- static void decompress_code (
- Word16 indx[], /* i : position and sign of 8 pulses (compressed) */
- Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */
- Word16 pos_indx[] /* o : position index of 8 pulses (position only) */
- )
- {
- Word16 i, ia, ib, MSBs, LSBs, MSBs0_24;
- for (i = 0; i < NB_TRACK_MR102; i++)
- {
- sign_indx[i] = indx[i]; move16 ();
- }
-
- /*
- First index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
- MSBs = indx[NB_TRACK]/8;
- LSBs = indx[NB_TRACK]%8;
- */
- MSBs = shr_ex(indx[NB_TRACK_MR102], 3);
- LSBs = indx[NB_TRACK_MR102] & 7; logic16 ();
- decompress10 (MSBs, LSBs, 0, 4, 1, pos_indx);
-
- /*
- Second index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
- MSBs = indx[NB_TRACK+1]/8;
- LSBs = indx[NB_TRACK+1]%8;
- */
- MSBs = shr_ex(indx[NB_TRACK_MR102+1], 3);
- LSBs = indx[NB_TRACK_MR102+1] & 7; logic16 ();
- decompress10 (MSBs, LSBs, 2, 6, 5, pos_indx);
-
- /*
- Third index: 10x10 -> 2x5x2x5-> 25x2x2 -> 5+1x2 bits
- MSBs = indx[NB_TRACK+2]/4;
- LSBs = indx[NB_TRACK+2]%4;
- MSBs0_24 = (MSBs*25+12)/32;
- if ((MSBs0_24/5)%2==1)
- pos_indx[3] = (4-(MSBs0_24%5))*2 + LSBs%2;
- else
- pos_indx[3] = (MSBs0_24%5)*2 + LSBs%2;
- pos_indx[7] = (MSBs0_24/5)*2 + LSBs/2;
- */
- MSBs = shr_ex(indx[NB_TRACK_MR102+2], 2);
- LSBs = indx[NB_TRACK_MR102+2] & 3; logic16 ();
- MSBs0_24 = shr_ex(add_ex(extract_l_ex(L_shr_ex(L_mult_ex(MSBs, 25), 1)), 12), 5);
-
- ia = mult_ex(MSBs0_24, 6554) & 1;
- ib = sub_ex(MSBs0_24, extract_l_ex(L_shr_ex(L_mult_ex(mult_ex(MSBs0_24, 6554), 5), 1)));
- test ();
- if (sub_ex(ia, 1) == 0)
- {
- ib = sub_ex(4, ib);
- }
- pos_indx[3] = add_ex(shl_ex(ib, 1), (LSBs & 1)); logic16 ();
-
- ia = shl_ex(mult_ex(MSBs0_24, 6554), 1);
- pos_indx[7] = add_ex(ia, shr_ex(LSBs, 1));
- }
- /*
- ********************************************************************************
- * PUBLIC PROGRAM CODE
- ********************************************************************************
- */
- /*************************************************************************
- *
- * FUNCTION: dec_8i40_31bits()
- *
- * PURPOSE: Builds the innovative codevector from the received
- * index of algebraic codebook.
- *
- * See c8_31pf.c for more details about the algebraic codebook structure.
- *
- *************************************************************************/
- void dec_8i40_31bits (
- Word16 index[], /* i : index of 8 pulses (sign+position) */
- Word16 cod[] /* o : algebraic (fixed) codebook excitation */
- )
- {
- Word16 i, j, pos1, pos2, sign;
- Word16 linear_signs[NB_TRACK_MR102];
- Word16 linear_codewords[NB_PULSE];
-
- for (i = 0; i < L_CODE; i++)
- {
- cod[i] = 0; move16 ();
- }
-
- decompress_code (index, linear_signs, linear_codewords);
-
- /* decode the positions and signs of pulses and build the codeword */
- for (j = 0; j < NB_TRACK_MR102; j++)
- {
- /* compute index i */
-
- i = linear_codewords[j];
- i = extract_l_ex (L_shr_ex (L_mult_ex (i, 4), 1));
- pos1 = add_ex (i, j); /* position of pulse "j" */
-
- test ();
- if (linear_signs[j] == 0)
- {
- sign = POS_CODE; move16 (); /* +1.0 */
- }
- else
- {
- sign = -NEG_CODE; move16 (); /* -1.0 */
- }
-
- cod[pos1] = sign; move16 ();
-
- /* compute index i */
-
- i = linear_codewords[add_ex (j, 4)];
- i = extract_l_ex (L_shr_ex (L_mult_ex (i, 4), 1));
- pos2 = add_ex (i, j); /* position of pulse "j+4" */
-
- test ();
- if (sub_ex (pos2, pos1) < 0)
- {
- sign = negate_ex (sign);
- }
- cod[pos2] = add_ex (cod[pos2], sign); move16 ();
- }
-
- return;
- }
|