annotate libtwamr/if1_unpack.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 /*
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our function for unpacking bits from AMR IF1
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and reshuffling them into the codec's natural bit order.
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
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 #include <stdint.h>
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
7 #include "tw_amr.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
8 #include "typedef.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
9 #include "namespace.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
10 #include "int_defs.h"
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
11 #include "if1_func.h"
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
13 static inline Word16 msb_get_bit(const uint8_t *buf, Word16 bn)
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
14 {
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
15 Word16 pos_byte = bn >> 3;
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
16 Word16 pos_bit = 7 - (bn & 7);
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
18 return (buf[pos_byte] >> pos_bit) & 1;
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
19 }
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
20
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
21 static void unpack_bits(const uint8_t *if1_bytes, Word16 *codec_bits,
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
22 Word16 nbits, const uint8_t *table)
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
24 Word16 n, nb;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 for (n = 0; n < nbits; n++) {
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (table)
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 nb = table[n];
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 else
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 nb = n;
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 codec_bits[nb] = msb_get_bit(if1_bytes, n);
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
35 void if1_unpack_bytes(enum Mode mode, const uint8_t *if1_bytes,
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
36 Word16 *serial_bits)
214
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 switch (mode) {
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 case MR475:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
40 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_475, sort_475);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
41 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 case MR515:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
43 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_515, sort_515);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
44 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 case MR59:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
46 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_59, sort_59);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
47 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case MR67:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
49 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_67, sort_67);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
50 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case MR74:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
52 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_74, sort_74);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
53 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case MR795:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
55 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_795, sort_795);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
56 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 case MR102:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
58 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_102, sort_102);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
59 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 case MR122:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
61 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_122, sort_122);
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
62 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 case MRDTX:
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
64 unpack_bits(if1_bytes, serial_bits, AMR_NBITS_SID,
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 (const uint8_t *) 0);
441
ebe499058c63 libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents: 214
diff changeset
66 return;
214
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
934cf92a1c45 amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }