comparison tchtools/efr2dsp.c @ 906:94890123a74f

tchtools: new program fc-efr2tch
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Dec 2022 10:05:46 +0000
parents
children
comparison
equal deleted inserted replaced
905:546bf873ccc8 906:94890123a74f
1 /*
2 * The utility function implemented in this module constructs a 33-byte
3 * frame for loading into Calypso DSP TCH UL buffer from a standard
4 * 244-bit EFR codec frame in the RTP encoding format of ETSI TS 101 318.
5 */
6
7 #include <sys/types.h>
8 #include <string.h>
9 #include <strings.h>
10
11 static const u_short efr_to_tidsp_table[244] = {
12 50, 24, 25, 37, 38, 43, 44, 26, 42, 27, 39, 40,
13 45, 51, 52, 41, 46, 28, 29, 47, 53, 77, 78, 30,
14 54, 55, 79, 56, 80, 109, 110, 111, 112, 113, 114, 115,
15 180, 181, 0, 1, 2, 3, 4, 5, 20, 31, 32, 16,
16 73, 105, 157, 81, 118, 138, 165, 82, 119, 139, 166, 83,
17 120, 140, 167, 84, 121, 141, 168, 85, 122, 186, 200, 204,
18 224, 244, 205, 225, 245, 206, 226, 246, 207, 227, 247, 208,
19 228, 248, 17, 61, 101, 153, 161, 12, 13, 22, 35, 48,
20 116, 18, 74, 106, 158, 86, 123, 142, 169, 87, 124, 143,
21 170, 88, 125, 144, 171, 89, 126, 145, 172, 90, 127, 189,
22 201, 209, 229, 249, 210, 230, 250, 211, 231, 251, 212, 232,
23 252, 213, 233, 253, 19, 62, 102, 154, 162, 6, 7, 8,
24 9, 10, 11, 21, 33, 34, 57, 75, 107, 159, 91, 128,
25 146, 173, 92, 129, 147, 174, 93, 130, 148, 175, 94, 131,
26 149, 176, 95, 132, 192, 202, 214, 234, 254, 215, 235, 255,
27 216, 236, 256, 217, 237, 257, 218, 238, 258, 59, 63, 103,
28 155, 163, 14, 15, 23, 36, 49, 117, 58, 76, 108, 160,
29 96, 133, 150, 177, 97, 134, 198, 199, 98, 135, 151, 178,
30 99, 136, 152, 179, 100, 137, 195, 203, 219, 239, 259, 220,
31 240, 260, 221, 241, 261, 222, 242, 262, 223, 243, 263, 60,
32 64, 104, 156, 164
33 };
34
35 static int
36 msb_get_bit(buf, bn)
37 u_char *buf;
38 {
39 int pos_byte = bn >> 3;
40 int pos_bit = 7 - (bn & 7);
41
42 return (buf[pos_byte] >> pos_bit) & 1;
43 }
44
45 static void
46 msb_set_bit(buf, bn)
47 u_char *buf;
48 {
49 int pos_byte = bn >> 3;
50 int pos_bit = 7 - (bn & 7);
51
52 buf[pos_byte] |= (1 << pos_bit);
53 }
54
55 void
56 efr_std_to_tidsp(inbytes, outbytes)
57 u_char *inbytes, *outbytes;
58 {
59 int i;
60
61 bzero(outbytes, 33);
62 for (i = 0; i < 244; i++) {
63 if (msb_get_bit(inbytes, i + 4))
64 msb_set_bit(outbytes, efr_to_tidsp_table[i]);
65 }
66 /* set repetition bits */
67 if (outbytes[23] & 0x20)
68 outbytes[23] |= 0x18;
69 if (outbytes[23] & 0x04)
70 outbytes[23] |= 0x03;
71 if (outbytes[24] & 0x80)
72 outbytes[24] |= 0x60;
73 if (outbytes[24] & 0x10)
74 outbytes[24] |= 0x0C;
75 }