comparison amrconv/if1_unpack.c @ 214:934cf92a1c45

amrconv: new program amr-ietf-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 20 Apr 2023 22:48:22 +0000
parents
children
comparison
equal deleted inserted replaced
213:46a6e6b6841a 214:934cf92a1c45
1 /*
2 * In this module we implement our function for unpacking bits from AMR IF1
3 * and reshuffling them into the codec's natural bit order.
4 */
5
6 #include <stdint.h>
7 #include "amr_defs.h"
8
9 extern const uint8_t amr_475_bit_order[95];
10 extern const uint8_t amr_515_bit_order[103];
11 extern const uint8_t amr_59_bit_order[118];
12 extern const uint8_t amr_67_bit_order[134];
13 extern const uint8_t amr_74_bit_order[148];
14 extern const uint8_t amr_795_bit_order[159];
15 extern const uint8_t amr_102_bit_order[204];
16 extern const uint8_t amr_122_bit_order[244];
17
18 static void
19 unpack_bits(if1_bytes, codec_bits, nbits, table)
20 uint8_t *if1_bytes, *codec_bits;
21 unsigned nbits;
22 const uint8_t *table;
23 {
24 unsigned n, nb;
25
26 for (n = 0; n < nbits; n++) {
27 if (table)
28 nb = table[n];
29 else
30 nb = n;
31 codec_bits[nb] = msb_get_bit(if1_bytes, n);
32 }
33 }
34
35 amr_if1_unpack(if1_bytes, codec_bits, mode)
36 uint8_t *if1_bytes, *codec_bits;
37 unsigned mode;
38 {
39 switch (mode) {
40 case MR475:
41 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_475,
42 amr_475_bit_order);
43 return(0);
44 case MR515:
45 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_515,
46 amr_515_bit_order);
47 return(0);
48 case MR59:
49 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_59,
50 amr_59_bit_order);
51 return(0);
52 case MR67:
53 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_67,
54 amr_67_bit_order);
55 return(0);
56 case MR74:
57 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_74,
58 amr_74_bit_order);
59 return(0);
60 case MR795:
61 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_795,
62 amr_795_bit_order);
63 return(0);
64 case MR102:
65 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_102,
66 amr_102_bit_order);
67 return(0);
68 case MR122:
69 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_122,
70 amr_122_bit_order);
71 return(0);
72 case MRDTX:
73 unpack_bits(if1_bytes, codec_bits, AMR_NBITS_SID,
74 (const uint8_t *) 0);
75 return(0);
76 default:
77 return(-1);
78 }
79 }