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