annotate sp_enc.c @ 2:aa7cc4333d95

Makefile: suppress some of the noise
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 Jun 2024 23:57:53 +0000
parents 9008dbc8ca74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /***************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * File Name: sp_enc.c
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Purpose: Contains speech encoder function. Calls are made to the
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * frame-based encoding functions (see sp_frm.c), and the subframe-
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * based encoding function (see sp_sfrm.c)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * Functions in this file (only 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * speechEncoder()
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 **************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 | Include Files |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "mathhalf.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #include "mathdp31.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "sp_rom.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "sp_dec.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "sp_frm.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "sp_sfrm.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #include "sp_enc.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #include "host.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include "vad.h"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 | Local Defines |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #define CG_INT_MACS 6 /* Number of Multiply-Accumulates in */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /* one interpolation */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #define ASCALE 0x0800
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #define LMAX 142 /* largest lag (integer sense) */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 #define LSMAX (LMAX+ CG_INT_MACS/2) /* Lag Search Array Length */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 #define NUM_CLOSED 3 /* Maximum number of lags searched */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /* in closed loop. */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #define LPCSTARTINDEX 25 /* Where the LPC analysis window
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 * starts */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 #define INBUFFSZ LPCSTARTINDEX + A_LEN /* Input buffer size */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 #define NUMSTARTUPSMP INBUFFSZ - F_LEN /* Number of samples needed */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /* at start up */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 #define NUMSTARTUPSMP_P1 INBUFFSZ - F_LEN + 1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 #define HPFSHIFT 1 /* no right shifts high pass shifts
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * speech */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 | State variables (globals) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 Shortword swOldR0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 Shortword swOldR0Index;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 struct NormSw psnsWSfrmEngSpace[2 * N_SUB];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Shortword pswHPFXState[4];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 Shortword pswHPFYState[8];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 Shortword pswOldFrmKs[NP];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Shortword pswOldFrmAs[NP];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Shortword pswOldFrmSNWCoefs[NP];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 Shortword pswWgtSpeechSpace[F_LEN + LMAX + CG_INT_MACS / 2];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 Shortword pswSpeech[INBUFFSZ]; /* input speech */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Shortword swPtch = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 | Global DTX variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 Shortword swTxGsHistPtr = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 Shortword pswCNVSCode1[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 pswCNVSCode2[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 pswCNGsp0Code[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 pswCNLpc[3],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 swCNR0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 extern Longword pL_GsHist[];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 extern LongwordRom ppLr_gsTable[4][32];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 /***************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 * FUNCTION NAME: speechEncoder
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 * PURPOSE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 * Performs GSM half-rate speech encoding on frame basis (160 samples).
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 * INPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 * pswSpeechIn[0:159] - input speech samples, 160 new samples per frame
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 * OUTPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 * pswFrmCodes[0:19] - output parameters, 18 speech parameters plus
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 * VAD and SP flags
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 * RETURN VALUE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 * None
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 * IMPLEMENTATION:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 * n/a
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 * REFERENCES: Sub-clause 4.1 of GSM Recomendation 06.20
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 * KEYWORDS: speechcoder, analysis
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 *************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 void speechEncoder(Shortword pswSpeechIn[], Shortword pswFrmCodes[])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 | Static Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 /* 1st point in analysis window */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 static Shortword *pswLpcStart = &pswSpeech[LPCSTARTINDEX];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 /* 1st point of new frame other than 1st */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 static Shortword *pswNewSpeech = &pswSpeech[NUMSTARTUPSMP];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 /* sample 0 of weighted speech */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 static Shortword *pswWgtSpeech = &pswWgtSpeechSpace[LSMAX];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 static struct NormSw *psnsWSfrmEng = &psnsWSfrmEngSpace[N_SUB];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 | Automatic Variables |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 int iVoicing, /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 iR0, /* bitAlloc and aflat */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 piVq[3], /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 iSi, /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 piLagCode[N_SUB], /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 piVSCode1[N_SUB], /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 piVSCode2[N_SUB], /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 piGsp0Code[N_SUB]; /* bitAlloc */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 short int siUVCode,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 siSi,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 i,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 j;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 Shortword swR0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 pswLagCode[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 pswVSCode1[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 pswVSCode2[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 pswGsp0Code[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 *pswLagListPtr,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 pswFrmKs[NP],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 pswFrmAs[NP],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 pswFrmSNWCoefs[NP],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 pswLagList[N_SUB * NUM_CLOSED],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 pswNumLagList[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 pswPitchBuf[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 pswHNWCoefBuf[N_SUB],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 ppswSNWCoefAs[N_SUB][NP],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 ppswSynthAs[N_SUB][NP];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 Shortword swSP,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 pswVadLags[4], /* VAD Parameters */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 swVadFlag; /* flag indicating voice activity
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 * detector state. 1 = speech or
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 * speech/signal present */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 struct NormSw
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 psnsSqrtRs[N_SUB];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 /*_________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 | Executable Code |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 |_________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 /* Speech frame processing */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 /* High pass filter the speech */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 /* ---------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 filt4_2nd(psrHPFCoefs, pswSpeechIn,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 pswHPFXState, pswHPFYState, F_LEN, HPFSHIFT);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 /* copy high passed filtered speech into encoder's speech buff */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 /*-------------------------------------------------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 for (i = 0; i < F_LEN; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 pswNewSpeech[i] = pswSpeechIn[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 /* Calculate and quantize LPC coefficients */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 /* --------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 aflat(pswLpcStart, &iR0, pswFrmKs, piVq,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 swPtch, &swVadFlag, &swSP);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 /* Lookup frame energy r0 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 /* ---------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 swR0 = psrR0DecTbl[iR0 * 2]; /* lookupR0 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 /* Generate the direct form coefs */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 /* ------------------------------ */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 if (!rcToADp(ASCALE, pswFrmKs, pswFrmAs))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 getNWCoefs(pswFrmAs, pswFrmSNWCoefs);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 for (i = 0; i < NP; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 pswFrmKs[i] = pswOldFrmKs[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 pswFrmAs[i] = pswOldFrmAs[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 pswFrmSNWCoefs[i] = pswOldFrmSNWCoefs[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 /* Interpolate, or otherwise get sfrm reflection coefs */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 /* --------------------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 getSfrmLpcTx(swOldR0, swR0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 pswOldFrmKs, pswOldFrmAs,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 pswOldFrmSNWCoefs,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 pswFrmKs, pswFrmAs,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 pswFrmSNWCoefs,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 pswSpeech,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 &siSi,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 psnsSqrtRs,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 ppswSynthAs, ppswSNWCoefAs);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 /* loose once bitAlloc done */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 iSi = siSi;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 /* Weight the entire speech frame */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 /* ------------------------------ */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 weightSpeechFrame(pswSpeech, ppswSynthAs[0], ppswSNWCoefAs[0],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 pswWgtSpeechSpace);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 /* Perform open-loop lag search, get harmonic-noise-weighting parameters */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 /* --------------------------------------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 openLoopLagSearch(&pswWgtSpeechSpace[LSMAX],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 swOldR0Index,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 (Shortword) iR0,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 &siUVCode,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 pswLagList,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 pswNumLagList,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 pswPitchBuf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 pswHNWCoefBuf,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 &psnsWSfrmEng[0],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 pswVadLags,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 swSP);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 iVoicing = siUVCode;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 /* Using open loop LTP data to calculate swPtch */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 /* parameter */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 /* -------------------------------------------- */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 periodicity_update(pswVadLags, &swPtch); /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 /* Subframe processing loop */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 /* ------------------------ */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 pswLagListPtr = pswLagList;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 for (giSfrmCnt = 0; giSfrmCnt < N_SUB; giSfrmCnt++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 if (swSP == 0) /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 { /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 pswVSCode1[giSfrmCnt] = pswCNVSCode1[giSfrmCnt]; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 pswVSCode2[giSfrmCnt] = pswCNVSCode2[giSfrmCnt]; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 pswGsp0Code[giSfrmCnt] = pswCNGsp0Code[giSfrmCnt]; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 } /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 sfrmAnalysis(&pswWgtSpeech[giSfrmCnt * S_LEN],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 siUVCode,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 psnsSqrtRs[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 ppswSNWCoefAs[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 pswLagListPtr,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 pswNumLagList[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 pswPitchBuf[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 pswHNWCoefBuf[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 &pswLagCode[giSfrmCnt], &pswVSCode1[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 &pswVSCode2[giSfrmCnt], &pswGsp0Code[giSfrmCnt],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 swSP);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 pswLagListPtr = &pswLagListPtr[pswNumLagList[giSfrmCnt]];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 /* copy comfort noise parameters, */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 /* update GS history */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 /* ------------------------------ */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 if (swSP == 0) /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 { /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 /* copy comfort noise frame parameter */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 /* ---------------------------------- */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 iR0 = swCNR0; /* quantized R0 index */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 for (i=0; i < 3; i++) /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 piVq[i] = pswCNLpc[i]; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 } /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 else /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 { /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 /* if swSP != 0, then update the GS history */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 /* -----------------------------------------*/ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 for (i=0; i < N_SUB; i++){ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 pL_GsHist[swTxGsHistPtr] = /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 ppLr_gsTable[siUVCode][pswGsp0Code[i]]; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 swTxGsHistPtr++; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 if (swTxGsHistPtr > ((OVERHANG-1)*N_SUB)-1) /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 swTxGsHistPtr=0; /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 } /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 } /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 /* End of frame processing, update frame based parameters */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 /* ------------------------------------------------------ */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 for (i = 0; i < N_SUB; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 piLagCode[i] = pswLagCode[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 piVSCode1[i] = pswVSCode1[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 piVSCode2[i] = pswVSCode2[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 piGsp0Code[i] = pswGsp0Code[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 swOldR0Index = (Shortword) iR0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 swOldR0 = swR0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 for (i = 0; i < NP; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 pswOldFrmKs[i] = pswFrmKs[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 pswOldFrmAs[i] = pswFrmAs[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 pswOldFrmSNWCoefs[i] = pswFrmSNWCoefs[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 /* Insert SID Codeword */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 /* ------------------- */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 if (swSP == 0) /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 { /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 iVoicing = 0x0003; /* 2 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 iSi = 0x0001; /* 1 bit */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 for (i=0; i < N_SUB; i++) /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 { /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 piVSCode1[i] = 0x01ff; /* 9 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 piGsp0Code[i] = 0x001f; /* 5 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 piLagCode[0] = 0x00ff; /* 8 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 piLagCode[1] = 0x000f; /* 4 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 piLagCode[2] = 0x000f; /* 4 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 piLagCode[3] = 0x000f; /* 4 bits */ /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 } /* DTX mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 /* Generate encoded parameter array */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 /* -------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 fillBitAlloc(iVoicing, iR0, piVq, iSi, piLagCode,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 piVSCode1, piVSCode2,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 piGsp0Code, swVadFlag, swSP, pswFrmCodes);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 /* delay the input speech by 1 frame */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 /*-----------------------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 for (i = 0, j = F_LEN; j < INBUFFSZ; i++, j++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 pswSpeech[i] = pswSpeech[j];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 }