\doxysection{amr.\+h} \label{amr_8h_source}\index{include/osmocom/netif/amr.h@{include/osmocom/netif/amr.h}} \begin{DoxyCode}{0} \DoxyCodeLine{1 \textcolor{preprocessor}{\#ifndef \_OSMO\_AMR\_H\_}} \DoxyCodeLine{2 \textcolor{preprocessor}{\#define \_OSMO\_AMR\_H\_}} \DoxyCodeLine{3 } \DoxyCodeLine{4 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{5 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{6 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{7 } \DoxyCodeLine{8 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{9 } \DoxyCodeLine{10 \textcolor{comment}{/* As defined by RFC3267: Adaptive Multi-\/Rate (AMR) */}} \DoxyCodeLine{11 } \DoxyCodeLine{12 \textcolor{comment}{/*}} \DoxyCodeLine{13 \textcolor{comment}{ * +-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/+-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/+-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{14 \textcolor{comment}{ * | payload header | table of contents | speech data ...}} \DoxyCodeLine{15 \textcolor{comment}{ * +-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/+-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/+-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{16 \textcolor{comment}{ */}} \DoxyCodeLine{17 } \DoxyCodeLine{18 \textcolor{comment}{/*}} \DoxyCodeLine{19 \textcolor{comment}{ * 4.3. Bandwidth-\/Efficient Mode:}} \DoxyCodeLine{20 \textcolor{comment}{ *}} \DoxyCodeLine{21 \textcolor{comment}{ * Summary from 4.3.4: Same as Octet aligned (see below) but without padding after header and ToC:}} \DoxyCodeLine{22 \textcolor{comment}{ * 0 1}} \DoxyCodeLine{23 \textcolor{comment}{ * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7}} \DoxyCodeLine{24 \textcolor{comment}{ * +-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+}} \DoxyCodeLine{25 \textcolor{comment}{ * | CMR |F| FT |Q|X X X X X X|}} \DoxyCodeLine{26 \textcolor{comment}{ * +-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+}} \DoxyCodeLine{27 \textcolor{comment}{ *}} \DoxyCodeLine{28 \textcolor{comment}{ * X means AMR payload (padding in case of FT=NO\_DATA).}} \DoxyCodeLine{29 \textcolor{comment}{ */}} \DoxyCodeLine{30 \textcolor{keyword}{struct }amr\_hdr\_bwe \{} \DoxyCodeLine{31 \textcolor{preprocessor}{\#if OSMO\_IS\_LITTLE\_ENDIAN}} \DoxyCodeLine{32 uint8\_t ft\_hi:3, \textcolor{comment}{/* coding mode highest part */}} \DoxyCodeLine{33 f:1,} \DoxyCodeLine{34 cmr:4; \textcolor{comment}{/* Codec Mode Request */}} \DoxyCodeLine{35 uint8\_t data\_start:6,} \DoxyCodeLine{36 q:1, \textcolor{comment}{/* OK (not damaged) at origin? */}} \DoxyCodeLine{37 ft\_lo:1; \textcolor{comment}{/* coding mode lowest bit */}} \DoxyCodeLine{38 \textcolor{preprocessor}{\#elif OSMO\_IS\_BIG\_ENDIAN}} \DoxyCodeLine{39 \textcolor{comment}{/* auto-\/generated from the little endian part above (libosmocore/contrib/struct\_endianness.py) */}} \DoxyCodeLine{40 uint8\_t cmr:4, f:1, ft\_hi:3;} \DoxyCodeLine{41 uint8\_t ft\_lo:1, q:1, data\_start:6;} \DoxyCodeLine{42 \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{43 uint8\_t data[0];} \DoxyCodeLine{44 \} \_\_attribute\_\_((packed));} \DoxyCodeLine{45 } \DoxyCodeLine{46 \textcolor{comment}{/* See diagram above: CMR (4) + F (1) + FT (4) + Q (1) = 10 */}} \DoxyCodeLine{47 \textcolor{preprocessor}{\#define AMR\_HDR\_BWE\_LEN\_BITS 10}} \DoxyCodeLine{48 } \DoxyCodeLine{49 \textcolor{comment}{/*}} \DoxyCodeLine{50 \textcolor{comment}{ * 4.4. Octet-\/aligned Mode:}} \DoxyCodeLine{51 \textcolor{comment}{ *}} \DoxyCodeLine{52 \textcolor{comment}{ * 4.4.1. The Payload Header:}} \DoxyCodeLine{53 \textcolor{comment}{ *}} \DoxyCodeLine{54 \textcolor{comment}{ * 0 1 2 3 4 5 6 7}} \DoxyCodeLine{55 \textcolor{comment}{ * +-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+}} \DoxyCodeLine{56 \textcolor{comment}{ * | CMR |X X X X|}} \DoxyCodeLine{57 \textcolor{comment}{ * +-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+}} \DoxyCodeLine{58 \textcolor{comment}{ *}} \DoxyCodeLine{59 \textcolor{comment}{ * According to: 3GPP TS 26.201 "{}AMR Wideband speech codec; Frame Structure"{},}} \DoxyCodeLine{60 \textcolor{comment}{ * version 5.0.0 (2001-\/03), 3rd Generation Partnership Project (3GPP):}} \DoxyCodeLine{61 \textcolor{comment}{ *}} \DoxyCodeLine{62 \textcolor{comment}{ * Possible Frame type / CMR values:}} \DoxyCodeLine{63 \textcolor{comment}{ *}} \DoxyCodeLine{64 \textcolor{comment}{ * 0-\/8 for AMR-\/WB (from 6.60 kbit/s to 23.85 kbit/s)}} \DoxyCodeLine{65 \textcolor{comment}{ * 9 (SID) confort noise.}} \DoxyCodeLine{66 \textcolor{comment}{ * 10-\/13 future use.}} \DoxyCodeLine{67 \textcolor{comment}{ * 14 means lost speech frame (only available for AMR-\/WB)}} \DoxyCodeLine{68 \textcolor{comment}{ * 15 means no data}} \DoxyCodeLine{69 \textcolor{comment}{ *}} \DoxyCodeLine{70 \textcolor{comment}{ * 4.4.2. The table of contents:}} \DoxyCodeLine{71 \textcolor{comment}{ *}} \DoxyCodeLine{72 \textcolor{comment}{ * 0 1 2 3 4 5 6 7}} \DoxyCodeLine{73 \textcolor{comment}{ * +-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+}} \DoxyCodeLine{74 \textcolor{comment}{ * |F| FT |Q|X X|}} \DoxyCodeLine{75 \textcolor{comment}{ * +-\/+-\/+-\/+-\/+-\/+-\/+-\/+-\/+}} \DoxyCodeLine{76 \textcolor{comment}{ *}} \DoxyCodeLine{77 \textcolor{comment}{ * X means padding.}} \DoxyCodeLine{78 \textcolor{comment}{ */}} \DoxyCodeLine{79 } \DoxyCodeLine{80 \textcolor{keyword}{struct }amr\_hdr \{} \DoxyCodeLine{81 \textcolor{preprocessor}{\#if OSMO\_IS\_LITTLE\_ENDIAN}} \DoxyCodeLine{82 \textcolor{comment}{/* Payload Header */}} \DoxyCodeLine{83 uint8\_t pad1:4,} \DoxyCodeLine{84 cmr:4; \textcolor{comment}{/* Codec Mode Request */}} \DoxyCodeLine{85 \textcolor{comment}{/* Table of Contents */}} \DoxyCodeLine{86 uint8\_t pad2:2,} \DoxyCodeLine{87 q:1, \textcolor{comment}{/* OK (not damaged) at origin? */}} \DoxyCodeLine{88 ft:4, \textcolor{comment}{/* coding mode */}} \DoxyCodeLine{89 f:1; \textcolor{comment}{/* followed by another speech frame? */}} \DoxyCodeLine{90 \textcolor{preprocessor}{\#elif OSMO\_IS\_BIG\_ENDIAN}} \DoxyCodeLine{91 \textcolor{comment}{/* auto-\/generated from the little endian part above (libosmocore/contrib/struct\_endianness.py) */}} \DoxyCodeLine{92 uint8\_t cmr:4, pad1:4;} \DoxyCodeLine{93 uint8\_t f:1, ft:4, q:1, pad2:2;} \DoxyCodeLine{94 \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{95 uint8\_t data[0];} \DoxyCodeLine{96 \} \_\_attribute\_\_((packed));} \DoxyCodeLine{97 } \DoxyCodeLine{98 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} *osmo\_amr\_get\_payload(\textcolor{keyword}{struct} amr\_hdr *amrh)} \DoxyCodeLine{99 \{} \DoxyCodeLine{100 \textcolor{keywordflow}{return} (uint8\_t *)amrh + \textcolor{keyword}{sizeof}(\textcolor{keyword}{struct }amr\_hdr);} \DoxyCodeLine{101 \}} \DoxyCodeLine{102 } \DoxyCodeLine{103 \textcolor{comment}{/* AMR voice frame type identifiers}} \DoxyCodeLine{104 \textcolor{comment}{ * See also 3GPP TS 26.101, Table 1a: Interpretation of Frame Type, Mode}} \DoxyCodeLine{105 \textcolor{comment}{ * Indication and Mode Request fields */}} \DoxyCodeLine{106 \textcolor{preprocessor}{\#define AMR\_FT\_0 0 }\textcolor{comment}{/* 4.75 */}\textcolor{preprocessor}{}} \DoxyCodeLine{107 \textcolor{preprocessor}{\#define AMR\_FT\_1 1 }\textcolor{comment}{/* 5.15 */}\textcolor{preprocessor}{}} \DoxyCodeLine{108 \textcolor{preprocessor}{\#define AMR\_FT\_2 2 }\textcolor{comment}{/* 5.90 */}\textcolor{preprocessor}{}} \DoxyCodeLine{109 \textcolor{preprocessor}{\#define AMR\_FT\_3 3 }\textcolor{comment}{/* 6.70 */}\textcolor{preprocessor}{}} \DoxyCodeLine{110 \textcolor{preprocessor}{\#define AMR\_FT\_4 4 }\textcolor{comment}{/* 7.40 */}\textcolor{preprocessor}{}} \DoxyCodeLine{111 \textcolor{preprocessor}{\#define AMR\_FT\_5 5 }\textcolor{comment}{/* 7.95 */}\textcolor{preprocessor}{}} \DoxyCodeLine{112 \textcolor{preprocessor}{\#define AMR\_FT\_6 6 }\textcolor{comment}{/* 10.2 */}\textcolor{preprocessor}{}} \DoxyCodeLine{113 \textcolor{preprocessor}{\#define AMR\_FT\_7 7 }\textcolor{comment}{/* 12.2 */}\textcolor{preprocessor}{}} \DoxyCodeLine{114 \textcolor{preprocessor}{\#define AMR\_FT\_SID 8 }\textcolor{comment}{/* AMR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{115 \textcolor{preprocessor}{\#define AMR\_FT\_GSM\_EFR\_SID 9 }\textcolor{comment}{/* GSM-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{116 \textcolor{preprocessor}{\#define AMR\_FT\_TDMA\_EFR\_SID 10 }\textcolor{comment}{/* TDMA-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{117 \textcolor{preprocessor}{\#define AMR\_FT\_PDC\_EFR\_SID 11 }\textcolor{comment}{/* PDC-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{118 \textcolor{comment}{/* version 16.0.0 Release 16: 12-\/14 for future use */}} \DoxyCodeLine{119 \textcolor{preprocessor}{\#define AMR\_FT\_NO\_DATA 15 }\textcolor{comment}{/* NO\_DATA */}\textcolor{preprocessor}{}} \DoxyCodeLine{120 \textcolor{preprocessor}{\#define AMR\_FT\_MAX 16 }\textcolor{comment}{/* INTERNAL, NO NOT USE OUTSIDE libosmo-\/netif */}\textcolor{preprocessor}{}} \DoxyCodeLine{121 } \DoxyCodeLine{122 \textcolor{comment}{/* AMR voice frame length (in bits).}} \DoxyCodeLine{123 \textcolor{comment}{ * See also RFC 3267, chapter 3.6.}} \DoxyCodeLine{124 \textcolor{comment}{ *}} \DoxyCodeLine{125 \textcolor{comment}{ * NOTE: These constants refer to the length of one AMR speech frame-\/block,}} \DoxyCodeLine{126 \textcolor{comment}{ * not counting CMR, TOC. */}} \DoxyCodeLine{127 \textcolor{preprocessor}{\#define AMR\_FT\_0\_LEN\_BITS 95 }\textcolor{comment}{/* 4.75 */}\textcolor{preprocessor}{}} \DoxyCodeLine{128 \textcolor{preprocessor}{\#define AMR\_FT\_1\_LEN\_BITS 103 }\textcolor{comment}{/* 5.15 */}\textcolor{preprocessor}{}} \DoxyCodeLine{129 \textcolor{preprocessor}{\#define AMR\_FT\_2\_LEN\_BITS 118 }\textcolor{comment}{/* 5.90 */}\textcolor{preprocessor}{}} \DoxyCodeLine{130 \textcolor{preprocessor}{\#define AMR\_FT\_3\_LEN\_BITS 134 }\textcolor{comment}{/* 6.70 */}\textcolor{preprocessor}{}} \DoxyCodeLine{131 \textcolor{preprocessor}{\#define AMR\_FT\_4\_LEN\_BITS 148 }\textcolor{comment}{/* 7.40 */}\textcolor{preprocessor}{}} \DoxyCodeLine{132 \textcolor{preprocessor}{\#define AMR\_FT\_5\_LEN\_BITS 159 }\textcolor{comment}{/* 7.95 */}\textcolor{preprocessor}{}} \DoxyCodeLine{133 \textcolor{preprocessor}{\#define AMR\_FT\_6\_LEN\_BITS 204 }\textcolor{comment}{/* 10.2 */}\textcolor{preprocessor}{}} \DoxyCodeLine{134 \textcolor{preprocessor}{\#define AMR\_FT\_7\_LEN\_BITS 244 }\textcolor{comment}{/* 12.2 */}\textcolor{preprocessor}{}} \DoxyCodeLine{135 \textcolor{preprocessor}{\#define AMR\_FT\_SID\_LEN\_BITS 39 }\textcolor{comment}{/* SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{136 \textcolor{preprocessor}{\#define AMR\_FT\_GSM\_EFR\_SID\_LEN\_BITS 43 }\textcolor{comment}{/* GSM-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{137 \textcolor{preprocessor}{\#define AMR\_FT\_TDMA\_EFR\_SID\_LEN\_BITS 38 }\textcolor{comment}{/* TDMA-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{138 \textcolor{preprocessor}{\#define AMR\_FT\_PDC\_EFR\_SID\_LEN\_BITS 37 }\textcolor{comment}{/* PDC-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{139 \textcolor{comment}{/* version 16.0.0 Release 16: 12-\/14 for future use */}} \DoxyCodeLine{140 \textcolor{preprocessor}{\#define AMR\_FT\_NO\_DATA\_LEN\_BITS 0 }\textcolor{comment}{/* NO\_DATA */}\textcolor{preprocessor}{}} \DoxyCodeLine{141 } \DoxyCodeLine{142 \textcolor{comment}{/* AMR voice frame length (in bytes, rounded).}} \DoxyCodeLine{143 \textcolor{comment}{ *}} \DoxyCodeLine{144 \textcolor{comment}{ * NOTE: These constants refer to the length of one AMR speech frame-\/block,}} \DoxyCodeLine{145 \textcolor{comment}{ * not counting CMR, TOC. */}} \DoxyCodeLine{146 \textcolor{preprocessor}{\#define AMR\_FT\_0\_LEN ((AMR\_FT\_0\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 4.75 */}\textcolor{preprocessor}{}} \DoxyCodeLine{147 \textcolor{preprocessor}{\#define AMR\_FT\_1\_LEN ((AMR\_FT\_1\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 5.15 */}\textcolor{preprocessor}{}} \DoxyCodeLine{148 \textcolor{preprocessor}{\#define AMR\_FT\_2\_LEN ((AMR\_FT\_2\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 5.90 */}\textcolor{preprocessor}{}} \DoxyCodeLine{149 \textcolor{preprocessor}{\#define AMR\_FT\_3\_LEN ((AMR\_FT\_3\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 6.70 */}\textcolor{preprocessor}{}} \DoxyCodeLine{150 \textcolor{preprocessor}{\#define AMR\_FT\_4\_LEN ((AMR\_FT\_4\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 7.40 */}\textcolor{preprocessor}{}} \DoxyCodeLine{151 \textcolor{preprocessor}{\#define AMR\_FT\_5\_LEN ((AMR\_FT\_5\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 7.95 */}\textcolor{preprocessor}{}} \DoxyCodeLine{152 \textcolor{preprocessor}{\#define AMR\_FT\_6\_LEN ((AMR\_FT\_6\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 10.2 */}\textcolor{preprocessor}{}} \DoxyCodeLine{153 \textcolor{preprocessor}{\#define AMR\_FT\_7\_LEN ((AMR\_FT\_7\_LEN\_BITS+7)/8) }\textcolor{comment}{/* 12.2 */}\textcolor{preprocessor}{}} \DoxyCodeLine{154 \textcolor{preprocessor}{\#define AMR\_FT\_SID\_LEN ((AMR\_FT\_SID\_LEN\_BITS+7)/8) }\textcolor{comment}{/* SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{155 \textcolor{preprocessor}{\#define AMR\_FT\_GSM\_EFR\_SID\_LEN ((AMR\_FT\_GSM\_EFR\_SID\_LEN\_BITS+7)/8) }\textcolor{comment}{/* GSM-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{156 \textcolor{preprocessor}{\#define AMR\_FT\_TDMA\_EFR\_SID\_LEN ((AMR\_FT\_TDMA\_EFR\_SID\_LEN\_BITS+7)/8) }\textcolor{comment}{/* TDMA-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{157 \textcolor{preprocessor}{\#define AMR\_FT\_PDC\_EFR\_SID\_LEN ((AMR\_FT\_PDC\_EFR\_SID\_LEN\_BITS+7)/8) }\textcolor{comment}{/* PDC-\/EFR SID */}\textcolor{preprocessor}{}} \DoxyCodeLine{158 \textcolor{comment}{/* version 16.0.0 Release 16: 12-\/14 for future use */}} \DoxyCodeLine{159 \textcolor{preprocessor}{\#define AMR\_FT\_NO\_DATA\_LEN ((AMR\_FT\_NO\_DATA\_LEN\_BITS+7)/8) }\textcolor{comment}{/* NO\_DATA */}\textcolor{preprocessor}{}} \DoxyCodeLine{160 } \DoxyCodeLine{161 \textcolor{keywordtype}{int} osmo\_amr\_ft\_valid(uint8\_t amr\_ft);} \DoxyCodeLine{162 \textcolor{keywordtype}{size\_t} osmo\_amr\_bytes(uint8\_t amr\_cmr);} \DoxyCodeLine{163 \textcolor{keywordtype}{size\_t} osmo\_amr\_bits(uint8\_t amr\_ft);} \DoxyCodeLine{164 } \DoxyCodeLine{165 \textcolor{keywordtype}{bool} osmo\_amr\_is\_oa(\textcolor{keyword}{const} uint8\_t *payload, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_len);} \DoxyCodeLine{166 \textcolor{keywordtype}{int} osmo\_amr\_oa\_to\_bwe(uint8\_t *payload, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_len);} \DoxyCodeLine{167 \textcolor{keywordtype}{int} osmo\_amr\_bwe\_to\_oa(uint8\_t *payload, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_len,} \DoxyCodeLine{168 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_maxlen);} \DoxyCodeLine{169 \textcolor{keywordtype}{int} osmo\_amr\_bwe\_to\_iuup(uint8\_t *payload, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_len);} \DoxyCodeLine{170 \textcolor{keywordtype}{int} osmo\_amr\_iuup\_to\_bwe(uint8\_t *payload, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_len,} \DoxyCodeLine{171 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} payload\_maxlen);} \DoxyCodeLine{172 \textcolor{keywordtype}{int} osmo\_amr\_bytes\_to\_ft(\textcolor{keywordtype}{size\_t} bytes);} \DoxyCodeLine{173 } \DoxyCodeLine{174 \textcolor{preprocessor}{\#endif}} \end{DoxyCode}