annotate libgsmefr/dtx_common.c @ 207:10f11a2d4042

pcap utils: fix bug in the case of RTP timestamp 16-bit rollover
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Feb 2023 19:56:45 +0000
parents 7bc011aceb7f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
c1d53064b410 libgsmefr: split dtx.c into dtx_{common,dec,enc}.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 67
diff changeset
1 /*
c1d53064b410 libgsmefr: split dtx.c into dtx_{common,dec,enc}.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 67
diff changeset
2 * This file is a product of splitting ETSI EFR dtx.c into parts;
c1d53064b410 libgsmefr: split dtx.c into dtx_{common,dec,enc}.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 67
diff changeset
3 * the present module is the common part for both the encoder and
c1d53064b410 libgsmefr: split dtx.c into dtx_{common,dec,enc}.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 67
diff changeset
4 * the decoder.
c1d53064b410 libgsmefr: split dtx.c into dtx_{common,dec,enc}.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 67
diff changeset
5 */
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
67
58b64224d4ac libgsmefr: dtx.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
7 #include "gsm_efr.h"
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "typedef.h"
67
58b64224d4ac libgsmefr: dtx.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
9 #include "namespace.h"
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "basic_op.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "cnst.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "sig_proc.h"
67
58b64224d4ac libgsmefr: dtx.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
13 #include "memops.h"
58b64224d4ac libgsmefr: dtx.c compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 66
diff changeset
14 #include "no_count.h"
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "dtx.h"
119
c1d53064b410 libgsmefr: split dtx.c into dtx_{common,dec,enc}.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 67
diff changeset
16 #include "dtx_defs.h"
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 * FUNCTION NAME: update_lsf_history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 * PURPOSE: Update the LSF parameter history. The LSF parameters kept
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 * in the buffer are used later for computing the reference
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * LSF parameter vector and the averaged LSF parameter vector.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INPUTS: lsf1[0..9] LSF vector of the 1st half of the frame
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * lsf2[0..9] LSF vector of the 2nd half of the frame
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 * lsf_old[0..DTX_HANGOVER-1][0..M-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 * Old LSF history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * OUTPUTS: lsf_old[0..DTX_HANGOVER-1][0..M-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 * Updated LSF history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 void update_lsf_history (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 Word16 lsf1[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 Word16 lsf2[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 Word16 lsf_old[DTX_HANGOVER][M]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 Word16 i, j, temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /* shift LSF data to make room for LSFs from current frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /* This can also be implemented by using circular buffering */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 for (i = DTX_HANGOVER - 1; i > 0; i--)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 for (j = 0; j < M; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 lsf_old[i][j] = lsf_old[i - 1][j]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 /* Store new LSF data to lsf_old buffer */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 for (i = 0; i < M; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 temp = add (shr (lsf1[i], 1), shr (lsf2[i], 1));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 lsf_old[0][i] = temp; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 * FUNCTION NAME: update_lsf_p_CN
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 * PURPOSE: Update the reference LSF parameter vector. The reference
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 * vector is computed by averaging the quantized LSF parameter
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 * vectors which exist in the LSF parameter history.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 * INPUTS: lsf_old[0..DTX_HANGOVER-1][0..M-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 * LSF parameter history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 * OUTPUTS: lsf_p_CN[0..9] Computed reference LSF parameter vector
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 void update_lsf_p_CN (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word16 lsf_old[DTX_HANGOVER][M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 Word16 lsf_p_CN[M]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 Word16 i, j;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 Word32 L_temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 for (j = 0; j < M; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 L_temp = L_mult (INV_DTX_HANGOVER, lsf_old[0][j]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 for (i = 1; i < DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 L_temp = L_mac (L_temp, INV_DTX_HANGOVER, lsf_old[i][j]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 lsf_p_CN[j] = round (L_temp); move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 * FUNCTION NAME: update_gcode0_CN
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 * PURPOSE: Update the reference fixed codebook gain parameter value.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 * The reference value is computed by averaging the quantized
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 * fixed codebook gain parameter values which exist in the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 * fixed codebook gain parameter history.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 * INPUTS: gain_code_old[0..4*DTX_HANGOVER-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 * fixed codebook gain parameter history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 * OUTPUTS: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 * RETURN VALUE: Computed reference fixed codebook gain
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 Word16 update_gcode0_CN (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 Word16 gain_code_old[4 * DTX_HANGOVER]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 Word16 i, j;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 Word32 L_temp, L_ret;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 L_ret = 0L; move32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 for (i = 0; i < DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 L_temp = L_mult (0x1fff, gain_code_old[4 * i]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 for (j = 1; j < 4; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 L_temp = L_mac (L_temp, 0x1fff, gain_code_old[4 * i + j]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 L_ret = L_mac (L_ret, INV_DTX_HANGOVER, extract_h (L_temp));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 return extract_h (L_ret);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 * FUNCTION NAME: build_CN_code
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 * PURPOSE: Compute the comfort noise fixed codebook excitation. The
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 * gains of the pulses are always +/-1.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 * INPUTS: *seed Old CN generator shift register state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 * OUTPUTS: cod[0..39] Generated comfort noise fixed codebook vector
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 * *seed Updated CN generator shift register state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 void build_CN_code (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 Word16 cod[],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 Word32 *seed
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 Word16 i, j, k;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 for (i = 0; i < L_SUBFR; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 cod[i] = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 for (k = 0; k < NB_PULSE; k++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 i = pseudonoise (seed, 2); /* generate pulse position */
191
7bc011aceb7f libgsmefr/dtx_common.c: perf opt
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
176 i *= 10;
7bc011aceb7f libgsmefr/dtx_common.c: perf opt
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
177 i += k;
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 j = pseudonoise (seed, 1); /* generate sign */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 if (j > 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 cod[i] = 4096; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 cod[i] = -4096; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 * FUNCTION NAME: pseudonoise
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 * PURPOSE: Generate a random integer value to use in comfort noise
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 * generation. The algorithm uses polynomial x^31 + x^3 + 1
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 * (length of PN sequence is 2^31 - 1).
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 * INPUTS: *shift_reg Old CN generator shift register state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 * OUTPUTS: *shift_reg Updated CN generator shift register state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 * RETURN VALUE: Generated random integer value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 Word16 pseudonoise (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 Word32 *shift_reg,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 Word16 no_bits
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 Word16 noise_bits, Sn, i;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 noise_bits = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 for (i = 0; i < no_bits; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 /* State n == 31 */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 test (); logic32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 if ((*shift_reg & 0x00000001L) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 Sn = 1; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 Sn = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 /* State n == 3 */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 test (); logic32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 if ((*shift_reg & 0x10000000L) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 Sn = Sn ^ 1; logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 Sn = Sn ^ 0; logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243
191
7bc011aceb7f libgsmefr/dtx_common.c: perf opt
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
244 noise_bits <<= 1;
7bc011aceb7f libgsmefr/dtx_common.c: perf opt
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
245 noise_bits |= *shift_reg & 1;
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 *shift_reg = L_shr (*shift_reg, 1); move32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 if (Sn & 1)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 *shift_reg = *shift_reg | 0x40000000L; move32 (); logic32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 return noise_bits;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }