comparison amrconv/if1_pack.c @ 215:4c4649a5fec3

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