annotate libtwamr/if1_pack.c @ 496:af70bf42eb1b

libgsmhr1: implement DHF const array
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 18 Jun 2024 00:15:46 +0000
parents ebe499058c63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
2 * In this module we implement our function for packing AMR codec bits
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
3 * from an array containing them in the codec's natural bit order
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
4 * into the octet form of AMR IF1 and RFC 4867.
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
8 #include "tw_amr.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
9 #include "typedef.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
10 #include "namespace.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
11 #include "int_defs.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
12 #include "if1_func.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
13
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
14 static inline void msb_set_bit(uint8_t *buf, Word16 bn, Word16 bit)
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
15 {
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
16 Word16 pos_byte = bn >> 3;
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
17 Word16 pos_bit = 7 - (bn & 7);
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
19 if (bit)
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
20 buf[pos_byte] |= (1 << pos_bit);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
21 else
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
22 buf[pos_byte] &= ~(1 << pos_bit);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
23 }
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
25 static void pack_bits(uint8_t *if1_bytes, const Word16 *src_bits, Word16 nbits,
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
26 const uint8_t *table)
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
28 Word16 n, nb;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 for (n = 0; n < nbits; n++) {
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (table)
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 nb = table[n];
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 else
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 nb = n;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
35 msb_set_bit(if1_bytes, n, src_bits[nb]);
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
39 void if1_pack_bytes(enum Mode mode, const Word16 *serial_bits,
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
40 uint8_t *if1_bytes)
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 switch (mode) {
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 case MR475:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
44 pack_bits(if1_bytes, serial_bits, AMR_NBITS_475, sort_475);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
45 if1_bytes[11] &= 0xFE;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
46 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 case MR515:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
48 pack_bits(if1_bytes, serial_bits, AMR_NBITS_515, sort_515);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
49 if1_bytes[12] &= 0xFE;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
50 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case MR59:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
52 pack_bits(if1_bytes, serial_bits, AMR_NBITS_59, sort_59);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
53 if1_bytes[14] &= 0xFC;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
54 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case MR67:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
56 pack_bits(if1_bytes, serial_bits, AMR_NBITS_67, sort_67);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
57 if1_bytes[16] &= 0xFC;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
58 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 case MR74:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
60 pack_bits(if1_bytes, serial_bits, AMR_NBITS_74, sort_74);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
61 if1_bytes[18] &= 0xF0;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
62 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 case MR795:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
64 pack_bits(if1_bytes, serial_bits, AMR_NBITS_795, sort_795);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
65 if1_bytes[19] &= 0xFE;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
66 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 case MR102:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
68 pack_bits(if1_bytes, serial_bits, AMR_NBITS_102, sort_102);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
69 if1_bytes[25] &= 0xF0;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
70 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 case MR122:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
72 pack_bits(if1_bytes, serial_bits, AMR_NBITS_122, sort_122);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
73 if1_bytes[30] &= 0xF0;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
74 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 case MRDTX:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
76 pack_bits(if1_bytes, serial_bits, AMR_NBITS_SID,
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 (const uint8_t *) 0);
215
4c4649a5fec3 amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
78 if1_bytes[4] &= 0xE0;
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
79 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }