annotate libhr/pack_frame.c @ 40:e1eabf554a75

libhr: small subset of WIP libgsmhr1
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 16:41:56 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module holds our gsmhr_pack_ts101318() function: packing a single
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * GSM-HR codec frame from an array of broken-down parameters into TS 101 318
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * format.
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "tw_gsmhr.h"
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 void gsmhr_pack_ts101318(const int16_t *params, uint8_t *payload)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 uint8_t *c = payload;
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 if (params[5]) {
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /* voiced modes */
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 *c++ = ((params[0] & 0x1F) << 3)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 | ((params[1] >> 8) & 0x7);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 *c++ = params[1] & 0xFF;
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 *c++ = ((params[2] >> 1) & 0xFF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 *c++ = ((params[2] & 0x1) << 7)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 | ((params[3] >> 1) & 0x7F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 *c++ = ((params[3] & 0x1) << 7)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 | ((params[4] & 0x1) << 6)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 | ((params[5] & 0x3) << 4)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 | ((params[6] >> 4) & 0xF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 *c++ = ((params[6] & 0xF) << 4)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 | ((params[7] >> 5) & 0xF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *c++ = ((params[7] & 0x1F) << 3)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 | ((params[8] >> 2) & 0x7);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 *c++ = ((params[8] & 0x3) << 6)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 | ((params[9] & 0xF) << 2)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 | ((params[10] >> 7) & 0x3);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *c++ = ((params[10] & 0x7F) << 1)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 | ((params[11] >> 4) & 0x1);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *c++ = ((params[11] & 0xF) << 4)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 | (params[12] & 0xF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 *c++ = ((params[13] >> 1) & 0xFF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *c++ = ((params[13] & 0x1) << 7)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 | ((params[14] & 0x1F) << 2)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 | ((params[15] >> 2) & 0x3);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *c++ = ((params[15] & 0x3) << 6)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 | ((params[16] >> 3) & 0x3F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 *c++ = ((params[16] & 0x7) << 5)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 | (params[17] & 0x1F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 } else {
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /* unvoiced mode */
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *c++ = ((params[0] & 0x1F) << 3)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 | ((params[1] >> 8) & 0x7);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *c++ = params[1] & 0xFF;
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *c++ = ((params[2] >> 1) & 0xFF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 *c++ = ((params[2] & 0x1) << 7)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 | ((params[3] >> 1) & 0x7F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 *c++ = ((params[3] & 0x1) << 7)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 | ((params[4] & 0x1) << 6)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 | ((params[5] & 0x3) << 4)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 | ((params[6] >> 3) & 0xF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *c++ = ((params[6] & 0x7) << 5)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 | ((params[7] >> 2) & 0x1F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 *c++ = ((params[7] & 0x3) << 6)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 | ((params[8] & 0x1F) << 1)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 | ((params[9] >> 6) & 0x1);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *c++ = ((params[9] & 0x3F) << 2)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 | ((params[10] >> 5) & 0x3);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 *c++ = ((params[10] & 0x1F) << 3)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 | ((params[11] >> 2) & 0x7);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 *c++ = ((params[11] & 0x3) << 6)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 | ((params[12] >> 1) & 0x3F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 *c++ = ((params[12] & 0x1) << 7)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 | (params[13] & 0x7F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 *c++ = ((params[14] & 0x1F) << 3)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 | ((params[15] >> 4) & 0x7);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 *c++ = ((params[15] & 0xF) << 4)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 | ((params[16] >> 3) & 0xF);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 *c++ = ((params[16] & 0x7) << 5)
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 | (params[17] & 0x1F);
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
e1eabf554a75 libhr: small subset of WIP libgsmhr1
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }