FreeCalypso > hg > gsm-codec-lib
annotate amrconv/if1_unpack.c @ 539:0daaae66b3f6
libtest: add TW-TS-005 write helper function
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 22 Sep 2024 00:21:16 +0000 |
parents | 934cf92a1c45 |
children |
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> |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "amr_defs.h" |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 extern const uint8_t amr_475_bit_order[95]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern const uint8_t amr_515_bit_order[103]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern const uint8_t amr_59_bit_order[118]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern const uint8_t amr_67_bit_order[134]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern const uint8_t amr_74_bit_order[148]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern const uint8_t amr_795_bit_order[159]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern const uint8_t amr_102_bit_order[204]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern const uint8_t amr_122_bit_order[244]; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static void |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 unpack_bits(if1_bytes, codec_bits, nbits, table) |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 uint8_t *if1_bytes, *codec_bits; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned nbits; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 const uint8_t *table; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned n, nb; |
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 |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 amr_if1_unpack(if1_bytes, codec_bits, mode) |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 uint8_t *if1_bytes, *codec_bits; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 unsigned mode; |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 switch (mode) { |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 case MR475: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_475, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 amr_475_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 case MR515: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_515, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 amr_515_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 case MR59: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_59, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 amr_59_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 case MR67: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_67, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 amr_67_bit_order); |
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 MR74: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_74, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 amr_74_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 case MR795: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_795, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 amr_795_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 case MR102: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_102, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 amr_102_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 case MR122: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_122, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 amr_122_bit_order); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(0); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 case MRDTX: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_SID, |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 (const uint8_t *) 0); |
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 default: |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 return(-1); |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
934cf92a1c45
amrconv: new program amr-ietf-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |