FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/b_cn_cod.c @ 255:07f936338de1
libtwamr: integrated up to b_cn_cod.c
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 05 Apr 2024 17:31:49 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 254:f931e704adc5 | 255:07f936338de1 |
|---|---|
| 1 /* | |
| 2 ******************************************************************************** | |
| 3 * | |
| 4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 | |
| 5 * R99 Version 3.3.0 | |
| 6 * REL-4 Version 4.1.0 | |
| 7 * | |
| 8 ******************************************************************************** | |
| 9 * | |
| 10 * File : b_cn_cod.c | |
| 11 * Purpose : Contains function for comfort noise generation. | |
| 12 * | |
| 13 ******************************************************************************** | |
| 14 */ | |
| 15 /* | |
| 16 ******************************************************************************** | |
| 17 * MODULE INCLUDE FILE AND VERSION ID | |
| 18 ******************************************************************************** | |
| 19 */ | |
| 20 #include "namespace.h" | |
| 21 #include "b_cn_cod.h" | |
| 22 | |
| 23 /* | |
| 24 ******************************************************************************** | |
| 25 * INCLUDE FILES | |
| 26 ******************************************************************************** | |
| 27 */ | |
| 28 #include "typedef.h" | |
| 29 #include "basic_op.h" | |
| 30 #include "oper_32b.h" | |
| 31 #include "no_count.h" | |
| 32 #include "cnst.h" | |
| 33 #include "window.h" | |
| 34 | |
| 35 /* | |
| 36 ******************************************************************************** | |
| 37 * LOCAL CONSTANTS | |
| 38 ******************************************************************************** | |
| 39 */ | |
| 40 #define NB_PULSE 10 /* number of random pulses in DTX operation */ | |
| 41 | |
| 42 /* | |
| 43 ******************************************************************************** | |
| 44 * PUBLIC PROGRAM CODE | |
| 45 ******************************************************************************** | |
| 46 */ | |
| 47 /************************************************************************* | |
| 48 * | |
| 49 * FUNCTION NAME: pseudonoise | |
| 50 * | |
| 51 *************************************************************************/ | |
| 52 Word16 pseudonoise ( | |
| 53 Word32 *shift_reg, /* i/o : Old CN generator shift register state */ | |
| 54 Word16 no_bits /* i : Number of bits */ | |
| 55 ) | |
| 56 { | |
| 57 Word16 noise_bits, Sn, i; | |
| 58 | |
| 59 noise_bits = 0; move16 (); | |
| 60 for (i = 0; i < no_bits; i++) | |
| 61 { | |
| 62 /* State n == 31 */ | |
| 63 test (); logic32 (); | |
| 64 if ((*shift_reg & 0x00000001L) != 0) | |
| 65 { | |
| 66 Sn = 1; move16 (); | |
| 67 } | |
| 68 else | |
| 69 { | |
| 70 Sn = 0; move16 (); | |
| 71 } | |
| 72 | |
| 73 /* State n == 3 */ | |
| 74 test (); logic32 (); | |
| 75 if ((*shift_reg & 0x10000000L) != 0) | |
| 76 { | |
| 77 Sn = Sn ^ 1; move16 (); logic16 (); | |
| 78 } | |
| 79 else | |
| 80 { | |
| 81 Sn = Sn ^ 0; move16 (); logic16 (); | |
| 82 } | |
| 83 | |
| 84 noise_bits = shl (noise_bits, 1); | |
| 85 noise_bits = noise_bits | (extract_l (*shift_reg) & 1); | |
| 86 logic16 (); logic16 (); move16 (); | |
| 87 | |
| 88 *shift_reg = L_shr (*shift_reg, 1); | |
| 89 test (); | |
| 90 if (Sn & 1) | |
| 91 { | |
| 92 *shift_reg = *shift_reg | 0x40000000L; move32 (); logic32 (); | |
| 93 } | |
| 94 } | |
| 95 return noise_bits; | |
| 96 } | |
| 97 | |
| 98 /*************************************************************************** | |
| 99 * | |
| 100 * Function : build_CN_code | |
| 101 * | |
| 102 ***************************************************************************/ | |
| 103 void build_CN_code ( | |
| 104 Word32 *seed, /* i/o : Old CN generator shift register state */ | |
| 105 Word16 cod[] /* o : Generated CN fixed codebook vector */ | |
| 106 ) | |
| 107 { | |
| 108 Word16 i, j, k; | |
| 109 | |
| 110 for (i = 0; i < L_SUBFR; i++) | |
| 111 { | |
| 112 cod[i] = 0; move16 (); | |
| 113 } | |
| 114 | |
| 115 for (k = 0; k < NB_PULSE; k++) | |
| 116 { | |
| 117 i = pseudonoise (seed, 2); /* generate pulse position */ | |
| 118 i = shr (extract_l (L_mult (i, 10)), 1); | |
| 119 i = add (i, k); | |
| 120 | |
| 121 j = pseudonoise (seed, 1); /* generate sign */ | |
| 122 | |
| 123 test (); | |
| 124 if (j > 0) | |
| 125 { | |
| 126 cod[i] = 4096; move16 (); | |
| 127 } | |
| 128 else | |
| 129 { | |
| 130 cod[i] = -4096; move16 (); | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 return; | |
| 135 } | |
| 136 | |
| 137 /************************************************************************* | |
| 138 * | |
| 139 * FUNCTION NAME: build_CN_param | |
| 140 * | |
| 141 *************************************************************************/ | |
| 142 void build_CN_param ( | |
| 143 Word16 *seed, /* i/o : Old CN generator shift register state */ | |
| 144 const Word16 n_param, /* i : number of params */ | |
| 145 const Word16 param_size_table[],/* i : size of params */ | |
| 146 Word16 parm[] /* o : CN Generated params */ | |
| 147 ) | |
| 148 { | |
| 149 Word16 i; | |
| 150 const Word16 *p; | |
| 151 | |
| 152 *seed = extract_l(L_add(L_shr(L_mult(*seed, 31821), 1), 13849L)); | |
| 153 | |
| 154 p = &window_200_40[*seed & 0x7F]; logic16(); | |
| 155 for(i=0; i< n_param;i++){ | |
| 156 move16 (); logic16(); logic16(); logic16(); | |
| 157 parm[i] = *p++ & ~(0xFFFF<<param_size_table[i]); | |
| 158 } | |
| 159 } |
