summaryrefslogtreecommitdiffstats
path: root/all_pairs/source/gsm_enc/gsm_enc.c
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
commit386b7d3366f1359a265da207a9cafa3edf553b64 (patch)
treec76120c2c138faed822e4ae386be6ef22a738a78 /all_pairs/source/gsm_enc/gsm_enc.c
parent54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff)
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'all_pairs/source/gsm_enc/gsm_enc.c')
-rw-r--r--all_pairs/source/gsm_enc/gsm_enc.c2072
1 files changed, 2072 insertions, 0 deletions
diff --git a/all_pairs/source/gsm_enc/gsm_enc.c b/all_pairs/source/gsm_enc/gsm_enc.c
new file mode 100644
index 0000000..cdac899
--- /dev/null
+++ b/all_pairs/source/gsm_enc/gsm_enc.c
@@ -0,0 +1,2072 @@
1/* gsm_enc_encode.c */
2/*
3 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
4 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
5 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
6 */
7
8#include "../extra.h"
9#include "private.h"
10
11/*
12 * Prototypes from add.c
13 */
14
15extern word gsm_enc_div (word num, word denum);
16
17extern word gsm_enc_sub (word a, word b);
18
19extern word gsm_enc_norm ( longword a );
20
21extern word gsm_enc_asl (word a, int n);
22
23extern word gsm_enc_asr (word a, int n);
24
25/*
26 * Inlined functions from add.h
27 */
28
29#define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
30 (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
31
32# define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
33 (SASR( ((longword)(a) * (longword)(b)), 15 ))
34
35# define GSM_L_ADD(a, b) \
36 ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
37 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
38 >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
39 : ((b) <= 0 ? (a) + (b) \
40 : (utmp = (ulongword)(a) + (ulongword)(b)) >= (ulongword)MAX_LONGWORD \
41 ? MAX_LONGWORD : a + b))
42
43#define GSM_ADD(a, b) \
44 ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
45 MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
46
47# define GSM_SUB(a, b) \
48 ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
49 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
50
51# define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
52
53#define saturate(x) \
54 ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))
55
56/* Use these if necessary:
57
58# define GSM_MULT_R(a, b) gsm_enc_mult_r(a, b)
59# define GSM_MULT(a, b) gsm_enc_mult(a, b)
60# define GSM_L_MULT(a, b) gsm_enc_L_mult(a, b)
61
62# define GSM_L_ADD(a, b) gsm_enc_L_add(a, b)
63# define GSM_ADD(a, b) gsm_enc_add(a, b)
64# define GSM_SUB(a, b) gsm_enc_sub(a, b)
65
66# define GSM_ABS(a) gsm_enc_abs(a)
67*/
68
69/*
70 * More prototypes from implementations..
71 */
72extern void gsm_enc_Gsm_Coder (
73 struct gsm_state * S,
74 word * s, /* [0..159] samples IN */
75 word * LARc, /* [0..7] LAR coefficients OUT */
76 word * Nc, /* [0..3] LTP lag OUT */
77 word * bc, /* [0..3] coded LTP gain OUT */
78 word * Mc, /* [0..3] RPE grid selection OUT */
79 word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
80 word * xMc /* [13*4] normalized RPE samples OUT */);
81
82extern void gsm_enc_Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
83 word * d, /* [0..39] residual signal IN */
84 word * dp, /* [-120..-1] d' IN */
85 word * e, /* [0..40] OUT */
86 word * dpp, /* [0..40] OUT */
87 word * Nc, /* correlation lag OUT */
88 word * bc /* gain factor OUT */);
89
90extern void gsm_enc_Gsm_LPC_Analysis (
91 word * s, /* 0..159 signals IN/OUT */
92 word * LARc); /* 0..7 LARc's OUT */
93
94extern void gsm_enc_Gsm_Preprocess (
95 struct gsm_state * S,
96 word * s, word * so);
97
98extern void gsm_enc_Gsm_Short_Term_Analysis_Filter (
99 struct gsm_state * S,
100 word * LARc, /* coded log area ratio [0..7] IN */
101 word * d /* st res. signal [0..159] IN/OUT */);
102
103void gsm_enc_Gsm_RPE_Encoding (
104 word * e, /* -5..-1][0..39][40..44 IN/OUT */
105 word * xmaxc, /* OUT */
106 word * Mc, /* OUT */
107 word * xMc); /* [0..12] OUT */
108
109
110/**************** end #include "private.h" **********************************/
111
112/*
113 * Interface
114 */
115
116typedef struct gsm_state * gsm;
117typedef short gsm_signal; /* signed 16 bit */
118typedef unsigned char gsm_byte;
119typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */
120
121#define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */
122
123#define GSM_PATCHLEVEL 6
124#define GSM_MINOR 0
125#define GSM_MAJOR 1
126
127#include "data.h"
128
129extern void gsm_enc_encode (gsm, gsm_signal *, gsm_byte *);
130
131extern int gsm_enc_explode (gsm, gsm_byte *, gsm_signal *);
132extern void gsm_enc_implode (gsm, gsm_signal *, gsm_byte *);
133
134
135/******************* end #include "gsm.h" **********************************/
136
137#define SAMPLES 20
138
139/*
140 Forward declaration of global variables
141*/
142
143struct gsm_state gsm_enc_state;
144gsm gsm_enc_state_ptr;
145volatile int gsm_enc_result;
146
147
148/* add.c */
149
150word gsm_enc_sub (word a, word b)
151{
152 longword diff = (longword)a - (longword)b;
153 return saturate(diff);
154}
155
156
157unsigned char gsm_enc_bitoff[ 256 ] = {
158 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
159 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
160 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
161 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
163 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
164 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
165 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
168 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
169 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
170 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
171 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
172 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
173 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
174};
175
176void gsm_enc_encode (gsm s, gsm_signal * source, gsm_byte * c)
177{
178 word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
179
180 gsm_enc_Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc);
181
182
183 /* variable size
184
185 GSM_MAGIC 4
186
187 LARc[0] 6
188 LARc[1] 6
189 LARc[2] 5
190 LARc[3] 5
191 LARc[4] 4
192 LARc[5] 4
193 LARc[6] 3
194 LARc[7] 3
195