annotate dev/pack_gsmfr_rtp.c @ 477:4c9222d95647

libtwamr encoder: always emit frame->mode = mode; In the original implementation of amr_encode_frame(), the 'mode' member of the output struct was set to 0xFF if the output frame type is TX_NO_DATA. This design was made to mimic the mode field (16-bit word) being set to 0xFFFF (or -1) in 3GPP test sequence format - but nothing actually depends on this struct member being set in any way, and amr_frame_to_tseq() generates the needed 0xFFFF on its own, based on frame->type being equal to TX_NO_DATA. It is simpler and more efficient to always set frame->mode to the actual encoding mode in amr_encode_frame(), and this new behavior has already been documented in doc/AMR-library-API description in anticipation of the present change.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 May 2024 22:30:42 +0000
parents e4ca04586118
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
258
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
276
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
2 * The function in this development-only module is a copy of
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
3 * gsmfr_pack_from_array() from work-in-progress libgsmfr2, which in turn
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
4 * was created to serve as a drop-in replacement for gsm_implode()
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
5 * from classic libgsm. The function is copied here to avoid the
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
6 * philosophical problem of libgsmfr2 being a dependency for developer aid
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
7 * programs used in the development of that library.
258
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #define GSM_FR_MAGIC 0xD
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
276
e4ca04586118 dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
Mychaela Falconia <falcon@freecalypso.org>
parents: 259
diff changeset
14 void gsmfr_pack_to_rtp(const int16_t *params, uint8_t *frame)
258
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 uint8_t *c = frame;
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned sub;
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 *c++ = (GSM_FR_MAGIC << 4)
259
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
20 | ((params[0] >> 2) & 0xF);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
21 *c++ = ((params[0] & 0x3) << 6)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
22 | (params[1] & 0x3F);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
23 *c++ = ((params[2] & 0x1F) << 3)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
24 | ((params[3] >> 2) & 0x7);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
25 *c++ = ((params[3] & 0x3) << 6)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
26 | ((params[4] & 0xF) << 2)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
27 | ((params[5] >> 2) & 0x3);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
28 *c++ = ((params[5] & 0x3) << 6)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
29 | ((params[6] & 0x7) << 3)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
30 | (params[7] & 0x7);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
31 params += 8;
258
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 for (sub = 0; sub < 4; sub++) {
259
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
33 *c++ = ((params[0] & 0x7F) << 1)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
34 | ((params[1] >> 1) & 0x1);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
35 *c++ = ((params[1] & 0x1) << 7)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
36 | ((params[2] & 0x3) << 5)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
37 | ((params[3] >> 1) & 0x1F);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
38 *c++ = ((params[3] & 0x1) << 7)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
39 | ((params[4] & 0x7) << 4)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
40 | ((params[5] & 0x7) << 1)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
41 | ((params[6] >> 2) & 0x1);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
42 *c++ = ((params[6] & 0x3) << 6)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
43 | ((params[7] & 0x7) << 3)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
44 | (params[8] & 0x7);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
45 *c++ = ((params[9] & 0x7) << 5)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
46 | ((params[10] & 0x7) << 2)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
47 | ((params[11] >> 1) & 0x3);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
48 *c++ = ((params[11] & 0x1) << 7)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
49 | ((params[12] & 0x7) << 4)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
50 | ((params[13] & 0x7) << 1)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
51 | ((params[14] >> 2) & 0x1);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
52 *c++ = ((params[14] & 0x3) << 6)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
53 | ((params[15] & 0x7) << 3)
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
54 | (params[16] & 0x7);
bebae251e5ee libgsmfr2: implement gsmfr_pack_from_array()
Mychaela Falconia <falcon@freecalypso.org>
parents: 258
diff changeset
55 params += 17;
258
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
c344b4f35eb7 libgsmfr2: implement gsmfr_pack_frame()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }