FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/ietf_out.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 | |
children |
comparison
equal
deleted
inserted
replaced
440:bc736a8654af | 441:ebe499058c63 |
---|---|
1 /* | |
2 * The function implemented in this module is responsible for turning | |
3 * struct amr_param_frame (encoder output) into an RFC 4867 payload. | |
4 */ | |
5 | |
6 #include <stdint.h> | |
7 #include "tw_amr.h" | |
8 #include "typedef.h" | |
9 #include "namespace.h" | |
10 #include "cnst.h" | |
11 #include "int_defs.h" | |
12 #include "if1_func.h" | |
13 | |
14 static const uint8_t total_bytes_per_ft[9] = | |
15 {13, 14, 16, 18, 20, 21, 27, 32, 6}; | |
16 | |
17 static const uint8_t first_octet_per_ft[9] = | |
18 {0x04, 0x0C, 0x14, 0x1C, 0x24, 0x2C, 0x34, 0x3C, 0x44}; | |
19 | |
20 unsigned amr_frame_to_ietf(const struct amr_param_frame *frame, uint8_t *bytes) | |
21 { | |
22 Word16 serial[MAX_SERIAL_SIZE]; | |
23 Word16 sti; | |
24 enum Mode ft; | |
25 | |
26 switch (frame->type) { | |
27 case TX_SPEECH_GOOD: | |
28 ft = frame->mode; | |
29 break; | |
30 case TX_SID_FIRST: | |
31 ft = MRDTX; | |
32 sti = 0; | |
33 break; | |
34 case TX_SID_UPDATE: | |
35 ft = MRDTX; | |
36 sti = 1; | |
37 break; | |
38 case TX_NO_DATA: | |
39 default: | |
40 bytes[0] = 0x7C; | |
41 return 1; | |
42 } | |
43 Prm2bits(ft, frame->param, serial); | |
44 bytes[0] = first_octet_per_ft[ft]; | |
45 if1_pack_bytes(ft, serial, bytes + 1); | |
46 if (ft == MRDTX) { | |
47 if (sti) | |
48 bytes[5] |= 0x10; | |
49 if (frame->mode & 1) | |
50 bytes[5] |= 0x08; | |
51 if (frame->mode & 2) | |
52 bytes[5] |= 0x04; | |
53 if (frame->mode & 4) | |
54 bytes[5] |= 0x02; | |
55 } | |
56 return total_bytes_per_ft[ft]; | |
57 } |