comparison libgsmfr2/pack_frame.c @ 258:c344b4f35eb7

libgsmfr2: implement gsmfr_pack_frame()
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Apr 2024 22:30:24 +0000
parents
children
comparison
equal deleted inserted replaced
257:77b7b7b7b384 258:c344b4f35eb7
1 /*
2 * This module holds our gsmfr_pack_frame() function: packing a single GSM-FR
3 * frame from a struct of broken-down parameters into libgsm/RTP format.
4 */
5
6 #include <stdint.h>
7 #include "tw_gsmfr.h"
8
9 #define GSM_FR_MAGIC 0xD
10
11 void gsmfr_pack_frame(const struct gsmfr_param_frame *param, uint8_t *frame)
12 {
13 uint8_t *c = frame;
14 unsigned sub;
15
16 *c++ = (GSM_FR_MAGIC << 4)
17 | ((param->LARc[0] >> 2) & 0xF);
18 *c++ = ((param->LARc[0] & 0x3) << 6)
19 | (param->LARc[1] & 0x3F);
20 *c++ = ((param->LARc[2] & 0x1F) << 3)
21 | ((param->LARc[3] >> 2) & 0x7);
22 *c++ = ((param->LARc[3] & 0x3) << 6)
23 | ((param->LARc[4] & 0xF) << 2)
24 | ((param->LARc[5] >> 2) & 0x3);
25 *c++ = ((param->LARc[5] & 0x3) << 6)
26 | ((param->LARc[6] & 0x7) << 3)
27 | (param->LARc[7] & 0x7);
28 for (sub = 0; sub < 4; sub++) {
29 *c++ = ((param->Nc[sub] & 0x7F) << 1)
30 | ((param->bc[sub] >> 1) & 0x1);
31 *c++ = ((param->bc[sub] & 0x1) << 7)
32 | ((param->Mc[sub] & 0x3) << 5)
33 | ((param->xmaxc[sub] >> 1) & 0x1F);
34 *c++ = ((param->xmaxc[sub] & 0x1) << 7)
35 | ((param->xMc[sub][0] & 0x7) << 4)
36 | ((param->xMc[sub][1] & 0x7) << 1)
37 | ((param->xMc[sub][2] >> 2) & 0x1);
38 *c++ = ((param->xMc[sub][2] & 0x3) << 6)
39 | ((param->xMc[sub][3] & 0x7) << 3)
40 | (param->xMc[sub][4] & 0x7);
41 *c++ = ((param->xMc[sub][5] & 0x7) << 5)
42 | ((param->xMc[sub][6] & 0x7) << 2)
43 | ((param->xMc[sub][7] >> 1) & 0x3);
44 *c++ = ((param->xMc[sub][7] & 0x1) << 7)
45 | ((param->xMc[sub][8] & 0x7) << 4)
46 | ((param->xMc[sub][9] & 0x7) << 1)
47 | ((param->xMc[sub][10] >> 2) & 0x1);
48 *c++ = ((param->xMc[sub][10] & 0x3) << 6)
49 | ((param->xMc[sub][11] & 0x7) << 3)
50 | (param->xMc[sub][12] & 0x7);
51 }
52 }