annotate libgsmefr/dtx.c @ 66:824ff833bda9

libgsmefr/dtx.c: initial import from ETSI code
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 26 Nov 2022 03:52:39 +0000
parents
children 58b64224d4ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /***************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * File Name: dtx.c
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Purpose: Contains functions for performing DTX operation and comfort
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * noise generation.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * Below is a listing of all the functions appearing in the file.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * The functions are arranged according to their purpose. Under
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * each heading, the ordering is hierarchical.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * Resetting of static variables of TX DTX:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * reset_tx_dtx()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 * Resetting of static variables of RX DTX:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 * reset_rx_dtx()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * TX DTX handler (called by the speech encoder):
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * tx_dtx()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 * RX DTX handler (called by the speech decoder):
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 * rx_dtx()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 * Encoding of comfort noise parameters into SID frame:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 * CN_encoding()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 * Encoding of SID codeword into SID frame:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * sid_codeword_encoding()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 * Detecting of SID codeword from a frame:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * sid_frame_detection()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * Update the LSF parameter history:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 * update_lsf_history()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 * Update the reference LSF parameter vector:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 * update_lsf_p_CN()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * Compute the averaged LSF parameter vector:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 * aver_lsf_history()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 * Update the fixed codebook gain parameter history of the encoder:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * update_gain_code_history_tx()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * Update the fixed codebook gain parameter history of the decoder:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 * update_gain_code_history_rx()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * Compute the unquantized fixed codebook gain:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 * compute_CN_excitation_gain()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * Update the reference fixed codebook gain:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * update_gcode0_CN()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 * Compute the averaged fixed codebook gain:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 * aver_gain_code_history()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 * Compute the comfort noise fixed codebook excitation:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * build_CN_code()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * Generate a random integer value:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * pseudonoise()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * Interpolate a comfort noise parameter value over the comfort noise
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * update period:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * interpolate_CN_param()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * Interpolate comfort noise LSF pparameter values over the comfort
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * noise update period:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 * interpolate_CN_lsf()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * interpolate_CN_param()
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 #include "typedef.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 #include "basic_op.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 #include "cnst.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 #include "sig_proc.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 #include "count.h"
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 #include "dtx.h"
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 /* Inverse values of DTX hangover period and DTX hangover period + 1 */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 #define INV_DTX_HANGOVER (0x7fff / DTX_HANGOVER)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 #define INV_DTX_HANGOVER_P1 (0x7fff / (DTX_HANGOVER+1))
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 #define NB_PULSE 10 /* Number of pulses in fixed codebook excitation */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 /* SID frame classification thresholds */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 #define VALID_SID_THRESH 2
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 #define INVALID_SID_THRESH 16
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 /* Constant DTX_ELAPSED_THRESHOLD is used as threshold for allowing
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 SID frame updating without hangover period in case when elapsed
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 time measured from previous SID update is below 24 */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 #define DTX_ELAPSED_THRESHOLD (24 + DTX_HANGOVER - 1)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 /* Index map for encoding and detecting SID codeword */
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 static const Word16 SID_codeword_bit_idx[95] =
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 45, 46, 48, 49, 50, 51, 52, 53, 54, 55,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 66, 67, 68, 94, 95, 96, 98, 99, 100, 101,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 112, 113, 114, 115, 116, 117, 118, 148, 149, 150,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 171, 196, 197, 198, 199, 200, 201, 202, 203, 204,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 205, 206, 207, 208, 209, 212, 213, 214, 215, 216,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 217, 218, 219, 220, 221
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 };
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 Word16 txdtx_ctrl; /* Encoder DTX control word */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 Word16 rxdtx_ctrl; /* Decoder DTX control word */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 Word16 CN_excitation_gain; /* Unquantized fixed codebook gain */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 Word32 L_pn_seed_tx; /* PN generator seed (encoder) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 Word32 L_pn_seed_rx; /* PN generator seed (decoder) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 Word16 rx_dtx_state; /* State of comfort noise insertion period */
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 static Word16 txdtx_hangover; /* Length of hangover period (VAD=0, SP=1) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 static Word16 rxdtx_aver_period;/* Length of hangover period (VAD=0, SP=1) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 static Word16 txdtx_N_elapsed; /* Measured time from previous SID frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 static Word16 rxdtx_N_elapsed; /* Measured time from previous SID frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 static Word16 old_CN_mem_tx[6]; /* The most recent CN parameters are stored*/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 static Word16 prev_SID_frames_lost; /* Counter for lost SID frames */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 static Word16 buf_p_tx; /* Circular buffer pointer for gain code
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 history update in tx */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 static Word16 buf_p_rx; /* Circular buffer pointer for gain code
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 history update in rx */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 Word16 lsf_old_tx[DTX_HANGOVER][M]; /* Comfort noise LSF averaging buffer */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 Word16 lsf_old_rx[DTX_HANGOVER][M]; /* Comfort noise LSF averaging buffer */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 Word16 gain_code_old_tx[4 * DTX_HANGOVER]; /* Comfort noise gain averaging
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 buffer */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 Word16 gain_code_old_rx[4 * DTX_HANGOVER]; /* Comfort noise gain averaging
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 buffer */
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 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 * FUNCTION NAME: reset_tx_dtx
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 * PURPOSE: Resets the static variables of the TX DTX handler to their
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 * initial values
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 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 void reset_tx_dtx ()
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 Word16 i;
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 /* suppose infinitely long speech period before start */
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 txdtx_hangover = DTX_HANGOVER;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 txdtx_N_elapsed = 0x7fff;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 txdtx_ctrl = TX_SP_FLAG | TX_VAD_FLAG;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 for (i = 0; i < 6; i++)
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 old_CN_mem_tx[i] = 0;
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
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 for (i = 0; i < DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 lsf_old_tx[i][0] = 1384;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 lsf_old_tx[i][1] = 2077;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 lsf_old_tx[i][2] = 3420;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 lsf_old_tx[i][3] = 5108;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 lsf_old_tx[i][4] = 6742;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 lsf_old_tx[i][5] = 8122;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 lsf_old_tx[i][6] = 9863;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 lsf_old_tx[i][7] = 11092;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 lsf_old_tx[i][8] = 12714;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 lsf_old_tx[i][9] = 13701;
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
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 for (i = 0; i < 4 * DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 gain_code_old_tx[i] = 0;
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
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 L_pn_seed_tx = PN_INITIAL_SEED;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 buf_p_tx = 0;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 return;
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 /*************************************************************************
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 * FUNCTION NAME: reset_rx_dtx
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 * PURPOSE: Resets the static variables of the RX DTX handler to their
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 * initial values
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 *
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
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 void reset_rx_dtx ()
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 Word16 i;
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 /* suppose infinitely long speech period before start */
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 rxdtx_aver_period = DTX_HANGOVER;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 rxdtx_N_elapsed = 0x7fff;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 rxdtx_ctrl = RX_SP_FLAG;
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 for (i = 0; i < DTX_HANGOVER; i++)
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 lsf_old_rx[i][0] = 1384;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 lsf_old_rx[i][1] = 2077;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 lsf_old_rx[i][2] = 3420;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 lsf_old_rx[i][3] = 5108;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 lsf_old_rx[i][4] = 6742;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 lsf_old_rx[i][5] = 8122;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 lsf_old_rx[i][6] = 9863;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 lsf_old_rx[i][7] = 11092;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 lsf_old_rx[i][8] = 12714;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 lsf_old_rx[i][9] = 13701;
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 for (i = 0; i < 4 * DTX_HANGOVER; i++)
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 gain_code_old_rx[i] = 0;
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 L_pn_seed_rx = PN_INITIAL_SEED;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 rx_dtx_state = CN_INT_PERIOD - 1;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 prev_SID_frames_lost = 0;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 buf_p_rx = 0;
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 return;
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
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 /*************************************************************************
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 * FUNCTION NAME: tx_dtx
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 * PURPOSE: DTX handler of the speech encoder. Determines when to add
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 * the hangover period to the end of the speech burst, and
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 * also determines when to use old SID parameters, and when
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 * to update the SID parameters. This function also initializes
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 * the pseudo noise generator shift register.
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 * Operation of the TX DTX handler is based on the VAD flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 * given as input from the speech encoder.
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 * INPUTS: VAD_flag Voice activity decision
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 * *txdtx_ctrl Old encoder DTX control word
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 * OUTPUTS: *txdtx_ctrl Updated encoder DTX control word
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 * L_pn_seed_tx Initialized pseudo noise generator shift
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 * register (global variable)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 *
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
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 void tx_dtx (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 Word16 VAD_flag,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 Word16 *txdtx_ctrl
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 {
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 /* N_elapsed (frames since last SID update) is incremented. If SID
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 is updated N_elapsed is cleared later in this function */
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 txdtx_N_elapsed = add (txdtx_N_elapsed, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 /* If voice activity was detected, reset hangover counter */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 if (sub (VAD_flag, 1) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 txdtx_hangover = DTX_HANGOVER; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 *txdtx_ctrl = TX_SP_FLAG | TX_VAD_FLAG; move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 if (txdtx_hangover == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 /* Hangover period is over, SID should be updated */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 txdtx_N_elapsed = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 /* Check if this is the first frame after hangover period */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 if ((*txdtx_ctrl & TX_HANGOVER_ACTIVE) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 *txdtx_ctrl = TX_PREV_HANGOVER_ACTIVE
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 | TX_SID_UPDATE; move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 L_pn_seed_tx = PN_INITIAL_SEED; move32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 *txdtx_ctrl = TX_SID_UPDATE; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 /* Hangover period is not over, update hangover counter */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 txdtx_hangover = sub (txdtx_hangover, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 /* Check if elapsed time from last SID update is greater than
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 threshold. If not, set SP=0 (although hangover period is not
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 over) and use old SID parameters for new SID frame.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 N_elapsed counter must be summed with hangover counter in order
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 to avoid erroneus SP=1 decision in case when N_elapsed is grown
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 bigger than threshold and hangover period is still active */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 if (sub (add (txdtx_N_elapsed, txdtx_hangover),
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 DTX_ELAPSED_THRESHOLD) < 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 /* old SID frame should be used */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 *txdtx_ctrl = TX_USE_OLD_SID; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 if ((*txdtx_ctrl & TX_HANGOVER_ACTIVE) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 *txdtx_ctrl = TX_PREV_HANGOVER_ACTIVE
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 | TX_HANGOVER_ACTIVE
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 | TX_SP_FLAG; move16 (); logic16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 *txdtx_ctrl = TX_HANGOVER_ACTIVE
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 | TX_SP_FLAG; move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 * FUNCTION NAME: rx_dtx
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 * PURPOSE: DTX handler of the speech decoder. Determines when to update
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 * the reference comfort noise parameters (LSF and gain) at the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 * end of the speech burst. Also classifies the incoming frames
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 * according to SID flag and BFI flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 * and determines when the transmission is active during comfort
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 * noise insertion. This function also initializes the pseudo
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 * noise generator shift register.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 * Operation of the RX DTX handler is based on measuring the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 * lengths of speech bursts and the lengths of the pauses between
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 * speech bursts to determine when there exists a hangover period
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 * at the end of a speech burst. The idea is to keep in sync with
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 * the TX DTX handler to be able to update the reference comfort
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 * noise parameters at the same time instances.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 * INPUTS: *rxdtx_ctrl Old decoder DTX control word
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 * TAF Time alignment flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 * bfi Bad frame indicator flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 * SID_flag Silence descriptor flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 * OUTPUTS: *rxdtx_ctrl Updated decoder DTX control word
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 * rx_dtx_state Updated state of comfort noise interpolation
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 * period (global variable)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 * L_pn_seed_rx Initialized pseudo noise generator shift
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 * register (global variable)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 void rx_dtx (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 Word16 *rxdtx_ctrl,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 Word16 TAF,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 Word16 bfi,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 Word16 SID_flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 Word16 frame_type;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 /* Frame classification according to bfi-flag and ternary-valued
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 SID flag. The frames between SID updates (not actually trans-
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 mitted) are also classified here; they will be discarded later
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 and provided with "NO TRANSMISSION"-flag */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 if ((sub (SID_flag, 2) == 0) && (bfi == 0))
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 frame_type = VALID_SID_FRAME; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 else if ((SID_flag == 0) && (bfi == 0))
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 frame_type = GOOD_SPEECH_FRAME; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 else if ((SID_flag == 0) && (bfi != 0))
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 frame_type = UNUSABLE_FRAME; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 frame_type = INVALID_SID_FRAME; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 /* Update of decoder state */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 /* Previous frame was classified as a speech frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 if ((*rxdtx_ctrl & RX_SP_FLAG) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 test (); test (); test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 if (sub (frame_type, VALID_SID_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 *rxdtx_ctrl = RX_FIRST_SID_UPDATE; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 else if (sub (frame_type, INVALID_SID_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 *rxdtx_ctrl = RX_FIRST_SID_UPDATE
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 | RX_INVALID_SID_FRAME; move16 (); logic16();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 else if (sub (frame_type, UNUSABLE_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
409 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 *rxdtx_ctrl = RX_SP_FLAG; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 else if (sub (frame_type, GOOD_SPEECH_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
413 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
414 *rxdtx_ctrl = RX_SP_FLAG; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
416 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
418 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
419 test (); test (); test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
420 if (sub (frame_type, VALID_SID_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 *rxdtx_ctrl = RX_CONT_SID_UPDATE; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 else if (sub (frame_type, INVALID_SID_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426 *rxdtx_ctrl = RX_CONT_SID_UPDATE
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 | RX_INVALID_SID_FRAME; move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
428 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429 else if (sub (frame_type, UNUSABLE_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431 *rxdtx_ctrl = RX_CNI_BFI; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 else if (sub (frame_type, GOOD_SPEECH_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 /* If the previous frame (during CNI period) was muted,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 raise the RX_PREV_DTX_MUTING flag */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 if ((*rxdtx_ctrl & RX_DTX_MUTING) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
440 *rxdtx_ctrl = RX_SP_FLAG | RX_FIRST_SP_FLAG
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 | RX_PREV_DTX_MUTING; move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442 logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
443 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 *rxdtx_ctrl = RX_SP_FLAG | RX_FIRST_SP_FLAG; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 if ((*rxdtx_ctrl & RX_SP_FLAG) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456 prev_SID_frames_lost = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 rx_dtx_state = CN_INT_PERIOD - 1; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461 /* First SID frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
463 if ((*rxdtx_ctrl & RX_FIRST_SID_UPDATE) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
465 prev_SID_frames_lost = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 rx_dtx_state = CN_INT_PERIOD - 1; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469 /* SID frame detected, but not the first SID */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471 if ((*rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 prev_SID_frames_lost = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475 test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 if (sub (frame_type, VALID_SID_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 rx_dtx_state = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480 else if (sub (frame_type, INVALID_SID_FRAME) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
483 if (sub(rx_dtx_state, (CN_INT_PERIOD - 1)) < 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
484 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485 rx_dtx_state = add(rx_dtx_state, 1); move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
487 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
489
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
490 /* Bad frame received in CNI mode */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
491 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
492 if ((*rxdtx_ctrl & RX_CNI_BFI) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
493 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
494 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
495 if (sub (rx_dtx_state, (CN_INT_PERIOD - 1)) < 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
496 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
497 rx_dtx_state = add (rx_dtx_state, 1); move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
498 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500 /* If an unusable frame is received during CNI period
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 when TAF == 1, the frame is classified as a lost
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502 SID frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504 if (sub (TAF, 1) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
505 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506 *rxdtx_ctrl = *rxdtx_ctrl | RX_LOST_SID_FRAME;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
508 prev_SID_frames_lost = add (prev_SID_frames_lost, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
509 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
510 else /* No transmission occurred */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
511 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
512 *rxdtx_ctrl = *rxdtx_ctrl | RX_NO_TRANSMISSION;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
513 move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
514 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
515
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
516 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
517 if (sub (prev_SID_frames_lost, 1) > 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
518 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
519 *rxdtx_ctrl = *rxdtx_ctrl | RX_DTX_MUTING;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
520 move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
521 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
522 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
523 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
524
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
525 /* N_elapsed (frames since last SID update) is incremented. If SID
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
526 is updated N_elapsed is cleared later in this function */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
527
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
528 rxdtx_N_elapsed = add (rxdtx_N_elapsed, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
529
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
530 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
531 if ((*rxdtx_ctrl & RX_SP_FLAG) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
532 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
533 rxdtx_aver_period = DTX_HANGOVER; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
534 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
535 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
536 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
537 test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
538 if (sub (rxdtx_N_elapsed, DTX_ELAPSED_THRESHOLD) > 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
539 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
540 *rxdtx_ctrl |= RX_UPD_SID_QUANT_MEM; move16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
541 rxdtx_N_elapsed = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
542 rxdtx_aver_period = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
543 L_pn_seed_rx = PN_INITIAL_SEED; move32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
544 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
545 else if (rxdtx_aver_period == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
546 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
547 rxdtx_N_elapsed = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
548 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
549 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
550 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
551 rxdtx_aver_period = sub (rxdtx_aver_period, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
552 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
553 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
554
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
555 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
556 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
557
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
558 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
559 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
560 * FUNCTION NAME: CN_encoding
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
561 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
562 * PURPOSE: Encoding of the comfort noise parameters into a SID frame.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
563 * Use old SID parameters if necessary. Set the parameter
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
564 * indices not used by comfort noise parameters to zero.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
565 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
566 * INPUTS: params[0..56] Comfort noise parameter frame from the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
567 * speech encoder
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
568 * txdtx_ctrl TX DTX handler control word
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
569 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
570 * OUTPUTS: params[0..56] Comfort noise encoded parameter frame
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
571 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
572 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
573 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
574 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
575
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
576 void CN_encoding (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
577 Word16 params[],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
578 Word16 txdtx_ctrl
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
579 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
580 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
581 Word16 i;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
582
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
583 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
584 if ((txdtx_ctrl & TX_SID_UPDATE) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
585 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
586 /* Store new CN parameters in memory to be used later as old
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
587 CN parameters */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
588
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
589 /* LPC parameter indices */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
590 for (i = 0; i < 5; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
591 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
592 old_CN_mem_tx[i] = params[i]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
593 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
594 /* Codebook index computed in last subframe */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
595 old_CN_mem_tx[5] = params[56]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
596 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
597 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
598 if ((txdtx_ctrl & TX_USE_OLD_SID) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
599 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
600 /* Use old CN parameters previously stored in memory */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
601 for (i = 0; i < 5; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
602 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
603 params[i] = old_CN_mem_tx[i]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
604 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
605 params[17] = old_CN_mem_tx[5]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
606 params[30] = old_CN_mem_tx[5]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
607 params[43] = old_CN_mem_tx[5]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
608 params[56] = old_CN_mem_tx[5]; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
609 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
610 /* Set all the rest of the parameters to zero (SID codeword will
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
611 be written later) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
612 for (i = 0; i < 12; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
613 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
614 params[i + 5] = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
615 params[i + 18] = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
616 params[i + 31] = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
617 params[i + 44] = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
618 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
619
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
620 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
621 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
622
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
623 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
624 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
625 * FUNCTION NAME: sid_codeword_encoding
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
626 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
627 * PURPOSE: Encoding of the SID codeword into the SID frame. The SID
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
628 * codeword consists of 95 bits, all set to '1'.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
629 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
630 * INPUTS: ser2[0..243] Serial-mode speech parameter frame before
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
631 * writing SID codeword into it
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
632 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
633 * OUTPUTS: ser2[0..243] Serial-mode speech parameter frame with
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
634 * SID codeword written into it
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
635 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
636 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
637 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
638 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
639
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
640 void sid_codeword_encoding (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
641 Word16 ser2[]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
642 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
643 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
644 Word16 i;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
645
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
646 for (i = 0; i < 95; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
647 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
648 ser2[SID_codeword_bit_idx[i]] = 1; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
649 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
650
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
651 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
652 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
653
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
654 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
655 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
656 * FUNCTION NAME: sid_frame_detection
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
657 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
658 * PURPOSE: Detecting of SID codeword from a received frame. The frames
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
659 * are classified into three categories based on how many bit
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
660 * errors occur in the SID codeword:
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
661 * - VALID SID FRAME
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
662 * - INVALID SID FRAME
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
663 * - SPEECH FRAME
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
664 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
665 * INPUTS: ser2[0..243] Received serial-mode speech parameter frame
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
666 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
667 * OUTPUTS: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
668 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
669 * RETURN VALUE: Ternary-valued SID classification flag
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
670 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
671 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
672
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
673 Word16 sid_frame_detection (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
674 Word16 ser2[]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
675 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
676 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
677 Word16 i, nbr_errors, sid;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
678
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
679 /* Search for bit errors in SID codeword */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
680 nbr_errors = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
681 for (i = 0; i < 95; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
682 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
683 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
684 if (ser2[SID_codeword_bit_idx[i]] == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
685 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
686 nbr_errors = add (nbr_errors, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
687 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
688 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
689
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
690 /* Frame classification */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
691 test (); test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
692 if (sub (nbr_errors, VALID_SID_THRESH) < 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
693 { /* Valid SID frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
694 sid = 2; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
695 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
696 else if (sub (nbr_errors, INVALID_SID_THRESH) < 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
697 { /* Invalid SID frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
698 sid = 1; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
699 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
700 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
701 { /* Speech frame */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
702 sid = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
703 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
704
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
705 return sid;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
706 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
707
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
708 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
709 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
710 * FUNCTION NAME: update_lsf_history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
711 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
712 * 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
713 * 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
714 * 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
715 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
716 * 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
717 * 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
718 * 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
719 * Old LSF history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
720 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
721 * 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
722 * Updated LSF history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
723 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
724 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
725 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
726 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
727
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
728 void update_lsf_history (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
729 Word16 lsf1[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
730 Word16 lsf2[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
731 Word16 lsf_old[DTX_HANGOVER][M]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
732 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
733 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
734 Word16 i, j, temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
735
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
736 /* 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
737 /* 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
738
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
739 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
740 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
741 for (j = 0; j < M; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
742 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
743 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
744 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
745 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
746
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
747 /* 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
748
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
749 for (i = 0; i < M; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
750 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
751 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
752 lsf_old[0][i] = temp; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
753 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
754
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
755 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
756 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
757
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
758 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
759 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
760 * FUNCTION NAME: update_lsf_p_CN
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
761 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
762 * 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
763 * 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
764 * 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
765 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
766 * 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
767 * LSF parameter history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
768 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
769 * 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
770 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
771 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
772 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
773 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
774
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
775 void update_lsf_p_CN (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
776 Word16 lsf_old[DTX_HANGOVER][M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
777 Word16 lsf_p_CN[M]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
778 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
779 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
780 Word16 i, j;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
781 Word32 L_temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
782
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
783 for (j = 0; j < M; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
784 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
785 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
786 for (i = 1; i < DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
787 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
788 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
789 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
790 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
791 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
792
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
793 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
794 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
795
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
796 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
797 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
798 * FUNCTION NAME: aver_lsf_history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
799 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
800 * PURPOSE: Compute the averaged LSF parameter vector. Computation is
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
801 * performed by averaging the LSF parameter vectors which exist
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
802 * in the LSF parameter history, together with the LSF
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
803 * parameter vectors of the current frame.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
804 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
805 * 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
806 * LSF parameter history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
807 * lsf1[0..M-1] 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
808 * lsf2[0..M-1] 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
809 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
810 * OUTPUTS: lsf_aver[0..M-1] Averaged LSF parameter vector
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
811 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
812 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
813 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
814 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
815
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
816 void aver_lsf_history (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
817 Word16 lsf_old[DTX_HANGOVER][M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
818 Word16 lsf1[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
819 Word16 lsf2[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
820 Word16 lsf_aver[M]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
821 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
822 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
823 Word16 i, j;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
824 Word32 L_temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
825
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
826 for (j = 0; j < M; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
827 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
828 L_temp = L_mult (0x3fff, lsf1[j]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
829 L_temp = L_mac (L_temp, 0x3fff, lsf2[j]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
830 L_temp = L_mult (INV_DTX_HANGOVER_P1, extract_h (L_temp));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
831
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
832 for (i = 0; i < DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
833 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
834 L_temp = L_mac (L_temp, INV_DTX_HANGOVER_P1, lsf_old[i][j]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
835 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
836
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
837 lsf_aver[j] = extract_h (L_temp); move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
838 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
839
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
840 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
841 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
842
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
843 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
844 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
845 * FUNCTION NAME: update_gain_code_history_tx
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
846 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
847 * PURPOSE: Update the fixed codebook gain parameter history of the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
848 * encoder. The fixed codebook gain parameters kept in the buffer
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
849 * are used later for computing the reference fixed codebook
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
850 * gain parameter value and the averaged fixed codebook gain
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
851 * parameter value.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
852 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
853 * INPUTS: new_gain_code New fixed codebook gain value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
854 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
855 * gain_code_old_tx[0..4*DTX_HANGOVER-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
856 * Old fixed codebook gain history of encoder
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
857 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
858 * OUTPUTS: gain_code_old_tx[0..4*DTX_HANGOVER-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
859 * Updated fixed codebook gain history of encoder
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
860 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
861 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
862 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
863 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
864
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
865 void update_gain_code_history_tx (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
866 Word16 new_gain_code,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
867 Word16 gain_code_old_tx[4 * DTX_HANGOVER]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
868 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
869 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
870
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
871 /* Circular buffer */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
872 gain_code_old_tx[buf_p_tx] = new_gain_code; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
873
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
874 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
875 if (sub (buf_p_tx, (4 * DTX_HANGOVER - 1)) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
876 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
877 buf_p_tx = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
878 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
879 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
880 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
881 buf_p_tx = add (buf_p_tx, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
882 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
883
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
884 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
885 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
886
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
887 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
888 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
889 * FUNCTION NAME: update_gain_code_history_rx
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
890 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
891 * PURPOSE: Update the fixed codebook gain parameter history of the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
892 * decoder. The fixed codebook gain parameters kept in the buffer
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
893 * are used later for computing the reference fixed codebook
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
894 * gain parameter value.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
895 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
896 * INPUTS: new_gain_code New fixed codebook gain value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
897 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
898 * gain_code_old_tx[0..4*DTX_HANGOVER-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
899 * Old fixed codebook gain history of decoder
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
900 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
901 * OUTPUTS: gain_code_old_tx[0..4*DTX_HANGOVER-1]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
902 * Updated fixed codebk gain history of decoder
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
903 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
904 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
905 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
906 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
907
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
908 void update_gain_code_history_rx (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
909 Word16 new_gain_code,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
910 Word16 gain_code_old_rx[4 * DTX_HANGOVER]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
911 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
912 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
913
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
914 /* Circular buffer */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
915 gain_code_old_rx[buf_p_rx] = new_gain_code; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
916
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
917 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
918 if (sub (buf_p_rx, (4 * DTX_HANGOVER - 1)) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
919 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
920 buf_p_rx = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
921 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
922 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
923 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
924 buf_p_rx = add (buf_p_rx, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
925 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
926
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
927 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
928 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
929
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
930 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
931 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
932 * FUNCTION NAME: compute_CN_excitation_gain
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
933 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
934 * PURPOSE: Compute the unquantized fixed codebook gain. Computation is
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
935 * based on the energy of the Linear Prediction residual signal.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
936 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
937 * INPUTS: res2[0..39] Linear Prediction residual signal
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
938 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
939 * OUTPUTS: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
940 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
941 * RETURN VALUE: Unquantized fixed codebook gain
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
942 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
943 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
944
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
945 Word16 compute_CN_excitation_gain (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
946 Word16 res2[L_SUBFR]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
947 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
948 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
949 Word16 i, norm, norm1, temp, overfl;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
950 Word32 L_temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
951
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
952 /* Compute the energy of the LP residual signal */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
953
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
954 norm = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
955 do
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
956 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
957 overfl = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
958
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
959 L_temp = 0L; move32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
960 for (i = 0; i < L_SUBFR; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
961 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
962 temp = shr (res2[i], norm);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
963 L_temp = L_mac (L_temp, temp, temp);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
964 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
965
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
966 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
967 if (L_sub (L_temp, MAX_32) == 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
968 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
969 norm = add (norm, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
970 overfl = 1; move16 (); /* Set the overflow flag */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
971 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
972 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
973 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
974 while (overfl != 0);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
975
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
976 L_temp = L_add (L_temp, 1L); /* Avoid the case of all zeros */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
977
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
978 /* Take the square root of the obtained energy value (sqroot is a 2nd
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
979 order Taylor series approximation) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
980
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
981 norm1 = norm_l (L_temp);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
982 temp = extract_h (L_shl (L_temp, norm1));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
983 L_temp = L_mult (temp, temp);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
984 L_temp = L_sub (805306368L, L_shr (L_temp, 3));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
985 L_temp = L_add (L_temp, L_mult (24576, temp));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
986
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
987 temp = extract_h (L_temp);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
988 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
989 if ((norm1 & 0x0001) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
990 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
991 temp = mult_r (temp, 23170);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
992 norm1 = sub (norm1, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
993 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
994 /* Divide the result of sqroot operation by sqroot(10) */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
995
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
996 temp = mult_r (temp, 10362);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
997
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
998 /* Re-scale to get the final value */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
999
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1000 norm1 = shr (norm1, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1001 norm1 = sub (norm1, norm);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1002
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1003 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1004 if (norm1 >= 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1005 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1006 temp = shr (temp, norm1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1007 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1008 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1009 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1010 temp = shl (temp, abs_s (norm1));
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1011 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1012
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1013 return temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1014 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1015
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1016 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1017 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1018 * FUNCTION NAME: update_gcode0_CN
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1019 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1020 * 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
1021 * 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
1022 * 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
1023 * fixed codebook gain parameter history.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1024 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1025 * 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
1026 * fixed codebook gain parameter history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1027 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1028 * OUTPUTS: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1029 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1030 * RETURN VALUE: Computed reference fixed codebook gain
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1031 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1032 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1033
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1034 Word16 update_gcode0_CN (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1035 Word16 gain_code_old[4 * DTX_HANGOVER]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1036 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1037 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1038 Word16 i, j;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1039 Word32 L_temp, L_ret;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1040
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1041 L_ret = 0L; move32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1042 for (i = 0; i < DTX_HANGOVER; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1043 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1044 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
1045 for (j = 1; j < 4; j++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1046 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1047 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
1048 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1049 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
1050 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1051
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1052 return extract_h (L_ret);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1053 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1054
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1055 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1056 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1057 * FUNCTION NAME: aver_gain_code_history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1058 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1059 * PURPOSE: Compute the averaged fixed codebook gain parameter value.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1060 * Computation is performed by averaging the fixed codebook
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1061 * gain parameter values which exist in the fixed codebook
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1062 * gain parameter history, together with the fixed codebook
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1063 * gain parameter value of the current subframe.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1064 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1065 * INPUTS: CN_excitation_gain
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1066 * Unquantized fixed codebook gain value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1067 * of the current subframe
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1068 * 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
1069 * fixed codebook gain parameter history
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1070 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1071 * OUTPUTS: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1072 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1073 * RETURN VALUE: Averaged fixed codebook gain value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1074 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1075 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1076
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1077 Word16 aver_gain_code_history (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1078 Word16 CN_excitation_gain,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1079 Word16 gain_code_old[4 * DTX_HANGOVER]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1080 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1081 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1082 Word16 i;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1083 Word32 L_ret;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1084
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1085 L_ret = L_mult (0x470, CN_excitation_gain);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1086
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1087 for (i = 0; i < (4 * DTX_HANGOVER); i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1088 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1089 L_ret = L_mac (L_ret, 0x470, gain_code_old[i]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1090 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1091 return extract_h (L_ret);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1092 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1093
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1094 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1095 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1096 * FUNCTION NAME: build_CN_code
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1097 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1098 * 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
1099 * gains of the pulses are always +/-1.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1100 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1101 * 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
1102 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1103 * 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
1104 * *seed Updated CN generator shift register state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1105 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1106 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1107 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1108 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1109
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1110 void build_CN_code (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1111 Word16 cod[],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1112 Word32 *seed
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1113 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1114 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1115 Word16 i, j, k;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1116
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1117 for (i = 0; i < L_SUBFR; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1118 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1119 cod[i] = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1120 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1121
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1122 for (k = 0; k < NB_PULSE; k++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1123 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1124 i = pseudonoise (seed, 2); /* generate pulse position */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1125 i = shr (extract_l (L_mult (i, 10)), 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1126 i = add (i, k);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1127
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1128 j = pseudonoise (seed, 1); /* generate sign */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1129
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1130 test ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1131 if (j > 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1132 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1133 cod[i] = 4096; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1134 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1135 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1136 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1137 cod[i] = -4096; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1138 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1139 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1140
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1141 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1142 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1143
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1144 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1145 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1146 * FUNCTION NAME: pseudonoise
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1147 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1148 * 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
1149 * 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
1150 * (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
1151 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1152 * 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
1153 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1154 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1155 * 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
1156 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1157 * RETURN VALUE: Generated random integer value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1158 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1159 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1160
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1161 Word16 pseudonoise (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1162 Word32 *shift_reg,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1163 Word16 no_bits
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1164 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1165 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1166 Word16 noise_bits, Sn, i;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1167
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1168 noise_bits = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1169 for (i = 0; i < no_bits; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1170 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1171 /* State n == 31 */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1172 test (); logic32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1173 if ((*shift_reg & 0x00000001L) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1174 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1175 Sn = 1; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1176 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1177 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1178 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1179 Sn = 0; move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1180 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1181
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1182 /* State n == 3 */
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1183 test (); logic32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1184 if ((*shift_reg & 0x10000000L) != 0)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1185 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1186 Sn = Sn ^ 1; logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1187 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1188 else
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1189 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1190 Sn = Sn ^ 0; logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1191 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1192
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1193 noise_bits = shl (noise_bits, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1194 noise_bits = noise_bits | (extract_l (*shift_reg) & 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1195 logic16 (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1196
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1197 *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
1198 test (); logic16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1199 if (Sn & 1)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1200 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1201 *shift_reg = *shift_reg | 0x40000000L; move32 (); logic32 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1202 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1203 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1204
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1205 return noise_bits;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1206 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1207
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1208 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1209 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1210 * FUNCTION NAME: interpolate_CN_param
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1211 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1212 * PURPOSE: Interpolate a comfort noise parameter value over the comfort
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1213 * noise update period.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1214 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1215 * INPUTS: old_param The older parameter of the interpolation
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1216 * (the endpoint the interpolation is started
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1217 * from)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1218 * new_param The newer parameter of the interpolation
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1219 * (the endpoint the interpolation is ended to)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1220 * rx_dtx_state State of the comfort noise insertion period
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1221 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1222 * OUTPUTS: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1223 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1224 * RETURN VALUE: Interpolated CN parameter value
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1225 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1226 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1227
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1228 Word16 interpolate_CN_param (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1229 Word16 old_param,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1230 Word16 new_param,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1231 Word16 rx_dtx_state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1232 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1233 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1234 static const Word16 interp_factor[CN_INT_PERIOD] =
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1235 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1236 0x0555, 0x0aaa, 0x1000, 0x1555, 0x1aaa, 0x2000,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1237 0x2555, 0x2aaa, 0x3000, 0x3555, 0x3aaa, 0x4000,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1238 0x4555, 0x4aaa, 0x5000, 0x5555, 0x5aaa, 0x6000,
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1239 0x6555, 0x6aaa, 0x7000, 0x7555, 0x7aaa, 0x7fff};
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1240 Word16 temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1241 Word32 L_temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1242
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1243 L_temp = L_mult (interp_factor[rx_dtx_state], new_param);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1244 temp = sub (0x7fff, interp_factor[rx_dtx_state]);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1245 temp = add (temp, 1);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1246 L_temp = L_mac (L_temp, temp, old_param);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1247 temp = round (L_temp);
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1248
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1249 return temp;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1250 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1251
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1252 /*************************************************************************
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1253 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1254 * FUNCTION NAME: interpolate_CN_lsf
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1255 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1256 * PURPOSE: Interpolate comfort noise LSF parameter vector over the comfort
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1257 * noise update period.
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1258 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1259 * INPUTS: lsf_old_CN[0..9]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1260 * The older LSF parameter vector of the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1261 * interpolation (the endpoint the interpolation
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1262 * is started from)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1263 * lsf_new_CN[0..9]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1264 * The newer LSF parameter vector of the
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1265 * interpolation (the endpoint the interpolation
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1266 * is ended to)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1267 * rx_dtx_state State of the comfort noise insertion period
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1268 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1269 * OUTPUTS: lsf_interp_CN[0..9]
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1270 * Interpolated LSF parameter vector
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1271 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1272 * RETURN VALUE: none
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1273 *
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1274 *************************************************************************/
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1275
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1276 void interpolate_CN_lsf (
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1277 Word16 lsf_old_CN[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1278 Word16 lsf_new_CN[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1279 Word16 lsf_interp_CN[M],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1280 Word16 rx_dtx_state
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1281 )
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1282 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1283 Word16 i;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1284
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1285 for (i = 0; i < M; i++)
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1286 {
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1287 lsf_interp_CN[i] = interpolate_CN_param (lsf_old_CN[i],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1288 lsf_new_CN[i],
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1289 rx_dtx_state); move16 ();
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1290 }
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1291
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1292 return;
824ff833bda9 libgsmefr/dtx.c: initial import from ETSI code
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1293 }