FreeCalypso > hg > gsm-codec-lib
annotate amrconv/if1_pack.c @ 490:4d80730683d4
libgsmhr1: implement TS 101 318 packing and unpacking
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 15 Jun 2024 05:33:35 +0000 |
parents | 4c4649a5fec3 |
children |
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> |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "amr_defs.h" |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern const uint8_t amr_475_bit_order[95]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern const uint8_t amr_515_bit_order[103]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern const uint8_t amr_59_bit_order[118]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern const uint8_t amr_67_bit_order[134]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern const uint8_t amr_74_bit_order[148]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern const uint8_t amr_795_bit_order[159]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern const uint8_t amr_102_bit_order[204]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern const uint8_t amr_122_bit_order[244]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static void |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
20 pack_bits(if1_bytes, codec_bits, nbits, table) |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint8_t *if1_bytes, *codec_bits; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned nbits; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 const uint8_t *table; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned n, nb; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 for (n = 0; n < nbits; n++) { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (table) |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 nb = table[n]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 else |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 nb = n; |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
32 msb_set_bit(if1_bytes, n, codec_bits[nb]); |
214
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 } |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
36 amr_if1_pack(if1_bytes, codec_bits, mode) |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 uint8_t *if1_bytes, *codec_bits; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 unsigned mode; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 switch (mode) { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 case MR475: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
42 pack_bits(if1_bytes, codec_bits, AMR_NBITS_475, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 amr_475_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
44 if1_bytes[11] &= 0xFE; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 case MR515: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
47 pack_bits(if1_bytes, codec_bits, AMR_NBITS_515, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 amr_515_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
49 if1_bytes[12] &= 0xFE; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 case MR59: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
52 pack_bits(if1_bytes, codec_bits, AMR_NBITS_59, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 amr_59_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
54 if1_bytes[14] &= 0xFC; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case MR67: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
57 pack_bits(if1_bytes, codec_bits, AMR_NBITS_67, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 amr_67_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
59 if1_bytes[16] &= 0xFC; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 case MR74: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
62 pack_bits(if1_bytes, codec_bits, AMR_NBITS_74, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 amr_74_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
64 if1_bytes[18] &= 0xF0; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 case MR795: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
67 pack_bits(if1_bytes, codec_bits, AMR_NBITS_795, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 amr_795_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
69 if1_bytes[19] &= 0xFE; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 case MR102: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
72 pack_bits(if1_bytes, codec_bits, AMR_NBITS_102, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 amr_102_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
74 if1_bytes[25] &= 0xF0; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 case MR122: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
77 pack_bits(if1_bytes, codec_bits, AMR_NBITS_122, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 amr_122_bit_order); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
79 if1_bytes[30] &= 0xF0; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 case MRDTX: |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
82 pack_bits(if1_bytes, codec_bits, AMR_NBITS_SID, |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 (const uint8_t *) 0); |
215
4c4649a5fec3
amrconv: new program amr-cod2ietf
Mychaela Falconia <falcon@freecalypso.org>
parents:
214
diff
changeset
|
84 if1_bytes[4] &= 0xE0; |
214
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 default: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 return(-1); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |