FreeCalypso > hg > gsm-codec-lib
comparison libgsmfr2/pack_frame2.c @ 259:bebae251e5ee
libgsmfr2: implement gsmfr_pack_from_array()
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Apr 2024 22:48:50 +0000 |
parents | libgsmfr2/pack_frame.c@c344b4f35eb7 |
children |
comparison
equal
deleted
inserted
replaced
258:c344b4f35eb7 | 259:bebae251e5ee |
---|---|
1 /* | |
2 * This module holds our gsmfr_pack_from_array() function: a drop-in | |
3 * replacement for gsm_implode() from classic libgsm. | |
4 */ | |
5 | |
6 #include <stdint.h> | |
7 #include "tw_gsmfr.h" | |
8 | |
9 #define GSM_FR_MAGIC 0xD | |
10 | |
11 void gsmfr_pack_from_array(const int16_t *params, uint8_t *frame) | |
12 { | |
13 uint8_t *c = frame; | |
14 unsigned sub; | |
15 | |
16 *c++ = (GSM_FR_MAGIC << 4) | |
17 | ((params[0] >> 2) & 0xF); | |
18 *c++ = ((params[0] & 0x3) << 6) | |
19 | (params[1] & 0x3F); | |
20 *c++ = ((params[2] & 0x1F) << 3) | |
21 | ((params[3] >> 2) & 0x7); | |
22 *c++ = ((params[3] & 0x3) << 6) | |
23 | ((params[4] & 0xF) << 2) | |
24 | ((params[5] >> 2) & 0x3); | |
25 *c++ = ((params[5] & 0x3) << 6) | |
26 | ((params[6] & 0x7) << 3) | |
27 | (params[7] & 0x7); | |
28 params += 8; | |
29 for (sub = 0; sub < 4; sub++) { | |
30 *c++ = ((params[0] & 0x7F) << 1) | |
31 | ((params[1] >> 1) & 0x1); | |
32 *c++ = ((params[1] & 0x1) << 7) | |
33 | ((params[2] & 0x3) << 5) | |
34 | ((params[3] >> 1) & 0x1F); | |
35 *c++ = ((params[3] & 0x1) << 7) | |
36 | ((params[4] & 0x7) << 4) | |
37 | ((params[5] & 0x7) << 1) | |
38 | ((params[6] >> 2) & 0x1); | |
39 *c++ = ((params[6] & 0x3) << 6) | |
40 | ((params[7] & 0x7) << 3) | |
41 | (params[8] & 0x7); | |
42 *c++ = ((params[9] & 0x7) << 5) | |
43 | ((params[10] & 0x7) << 2) | |
44 | ((params[11] >> 1) & 0x3); | |
45 *c++ = ((params[11] & 0x1) << 7) | |
46 | ((params[12] & 0x7) << 4) | |
47 | ((params[13] & 0x7) << 1) | |
48 | ((params[14] >> 2) & 0x1); | |
49 *c++ = ((params[14] & 0x3) << 6) | |
50 | ((params[15] & 0x7) << 3) | |
51 | (params[16] & 0x7); | |
52 params += 17; | |
53 } | |
54 } |