comparison dev/pack_gsmfr_rtp.c @ 276:e4ca04586118

dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 03:38:09 +0000
parents libgsmfr2/pack_frame2.c@bebae251e5ee
children
comparison
equal deleted inserted replaced
275:5fbb323b2978 276:e4ca04586118
1 /*
2 * The function in this development-only module is a copy of
3 * gsmfr_pack_from_array() from work-in-progress libgsmfr2, which in turn
4 * was created to serve as a drop-in replacement for gsm_implode()
5 * from classic libgsm. The function is copied here to avoid the
6 * philosophical problem of libgsmfr2 being a dependency for developer aid
7 * programs used in the development of that library.
8 */
9
10 #include <stdint.h>
11
12 #define GSM_FR_MAGIC 0xD
13
14 void gsmfr_pack_to_rtp(const int16_t *params, uint8_t *frame)
15 {
16 uint8_t *c = frame;
17 unsigned sub;
18
19 *c++ = (GSM_FR_MAGIC << 4)
20 | ((params[0] >> 2) & 0xF);
21 *c++ = ((params[0] & 0x3) << 6)
22 | (params[1] & 0x3F);
23 *c++ = ((params[2] & 0x1F) << 3)
24 | ((params[3] >> 2) & 0x7);
25 *c++ = ((params[3] & 0x3) << 6)
26 | ((params[4] & 0xF) << 2)
27 | ((params[5] >> 2) & 0x3);
28 *c++ = ((params[5] & 0x3) << 6)
29 | ((params[6] & 0x7) << 3)
30 | (params[7] & 0x7);
31 params += 8;
32 for (sub = 0; sub < 4; sub++) {
33 *c++ = ((params[0] & 0x7F) << 1)
34 | ((params[1] >> 1) & 0x1);
35 *c++ = ((params[1] & 0x1) << 7)
36 | ((params[2] & 0x3) << 5)
37 | ((params[3] >> 1) & 0x1F);
38 *c++ = ((params[3] & 0x1) << 7)
39 | ((params[4] & 0x7) << 4)
40 | ((params[5] & 0x7) << 1)
41 | ((params[6] >> 2) & 0x1);
42 *c++ = ((params[6] & 0x3) << 6)
43 | ((params[7] & 0x7) << 3)
44 | (params[8] & 0x7);
45 *c++ = ((params[9] & 0x7) << 5)
46 | ((params[10] & 0x7) << 2)
47 | ((params[11] >> 1) & 0x3);
48 *c++ = ((params[11] & 0x1) << 7)
49 | ((params[12] & 0x7) << 4)
50 | ((params[13] & 0x7) << 1)
51 | ((params[14] >> 2) & 0x1);
52 *c++ = ((params[14] & 0x3) << 6)
53 | ((params[15] & 0x7) << 3)
54 | (params[16] & 0x7);
55 params += 17;
56 }
57 }