FreeCalypso > hg > gsm-codec-lib
comparison libgsmhr1/pack_frame.c @ 490:4d80730683d4
libgsmhr1: implement TS 101 318 packing and unpacking
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 15 Jun 2024 05:33:35 +0000 |
parents | |
children | c275e57132f8 |
comparison
equal
deleted
inserted
replaced
489:f036e1de5b05 | 490:4d80730683d4 |
---|---|
1 /* | |
2 * This module holds our gsmhr_pack_ts101318() function: packing a single | |
3 * GSM-HR codec frame from an array of broken-down parameters into TS 101 318 | |
4 * format. | |
5 */ | |
6 | |
7 #include <stdint.h> | |
8 #include "tw_gsmhr.h" | |
9 | |
10 void gsmhr_pack_ts101318(const int16_t *params, uint8_t *payload) | |
11 { | |
12 uint8_t *c = payload; | |
13 | |
14 if (params[5]) { | |
15 /* voiced modes */ | |
16 *c++ = ((params[0] & 0x1F) << 3) | |
17 | ((params[1] >> 8) & 0x7); | |
18 *c++ = params[1] & 0xFF; | |
19 *c++ = ((params[2] >> 1) & 0xFF); | |
20 *c++ = ((params[2] & 0x1) << 7) | |
21 | ((params[3] >> 1) & 0x7F); | |
22 *c++ = ((params[3] & 0x1) << 7) | |
23 | ((params[4] & 0x1) << 6) | |
24 | ((params[5] & 0x3) << 4) | |
25 | ((params[6] >> 4) & 0xF); | |
26 *c++ = ((params[6] & 0xF) << 4) | |
27 | ((params[7] >> 5) & 0xF); | |
28 *c++ = ((params[7] & 0x1F) << 3) | |
29 | ((params[8] >> 2) & 0x7); | |
30 *c++ = ((params[8] & 0x3) << 6) | |
31 | ((params[9] & 0xF) << 2) | |
32 | ((params[10] >> 7) & 0x3); | |
33 *c++ = ((params[10] & 0x7F) << 1) | |
34 | ((params[11] >> 4) & 0x1); | |
35 *c++ = ((params[11] & 0xF) << 4) | |
36 | (params[12] & 0xF); | |
37 *c++ = ((params[13] >> 1) & 0xFF); | |
38 *c++ = ((params[13] & 0x1) << 7) | |
39 | ((params[14] & 0x1F) << 2) | |
40 | ((params[15] >> 2) & 0x3); | |
41 *c++ = ((params[15] & 0x3) << 6) | |
42 | ((params[16] >> 3) & 0x3F); | |
43 *c++ = ((params[16] & 0x7) << 5) | |
44 | (params[17] & 0x1F); | |
45 } else { | |
46 /* unvoiced modes */ | |
47 *c++ = ((params[0] & 0x1F) << 3) | |
48 | ((params[1] >> 8) & 0x7); | |
49 *c++ = params[1] & 0xFF; | |
50 *c++ = ((params[2] >> 1) & 0xFF); | |
51 *c++ = ((params[2] & 0x1) << 7) | |
52 | ((params[3] >> 1) & 0x7F); | |
53 *c++ = ((params[3] & 0x1) << 7) | |
54 | ((params[4] & 0x1) << 6) | |
55 | ((params[5] & 0x3) << 4) | |
56 | ((params[6] >> 3) & 0xF); | |
57 *c++ = ((params[6] & 0x7) << 5) | |
58 | ((params[7] >> 2) & 0x1F); | |
59 *c++ = ((params[7] & 0x3) << 6) | |
60 | ((params[8] & 0x1F) << 1) | |
61 | ((params[9] >> 6) & 0x1); | |
62 *c++ = ((params[9] & 0x3F) << 2) | |
63 | ((params[10] >> 5) & 0x3); | |
64 *c++ = ((params[10] & 0x1F) << 3) | |
65 | ((params[11] >> 2) & 0x7); | |
66 *c++ = ((params[11] & 0x3) << 6) | |
67 | ((params[12] >> 1) & 0x3F); | |
68 *c++ = ((params[12] & 0x1) << 7) | |
69 | (params[13] & 0x7F); | |
70 *c++ = ((params[14] & 0x1F) << 3) | |
71 | ((params[15] >> 4) & 0x7); | |
72 *c++ = ((params[15] & 0xF) << 4) | |
73 | ((params[16] >> 3) & 0xF); | |
74 *c++ = ((params[16] & 0x7) << 5) | |
75 | (params[17] & 0x1F); | |
76 } | |
77 } |