\doxysection{codec.\+h}
\label{codec_8h_source}\index{include/osmocom/codec/codec.h@{include/osmocom/codec/codec.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{4 }
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{6 \textcolor{preprocessor}{\#include <stdbool.h>}}
\DoxyCodeLine{7 }
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <osmocom/core/utils.h>}}
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <osmocom/core/bits.h>}}
\DoxyCodeLine{10 }
\DoxyCodeLine{11 \textcolor{comment}{/* TS 101318 Chapter 5.1: 260 bits + 4bit sig */}}
\DoxyCodeLine{12 \textcolor{preprocessor}{\#define GSM\_FR\_BYTES    33}}
\DoxyCodeLine{13 \textcolor{comment}{/* TS 101318 Chapter 5.2: 112 bits, no sig */}}
\DoxyCodeLine{14 \textcolor{preprocessor}{\#define GSM\_HR\_BYTES    14}}
\DoxyCodeLine{15 \textcolor{comment}{/* TS 101318 Chapter 5.3: 244 bits + 4bit sig */}}
\DoxyCodeLine{16 \textcolor{preprocessor}{\#define GSM\_EFR\_BYTES   31}}
\DoxyCodeLine{17 }
\DoxyCodeLine{18 \textcolor{comment}{/* Number of bytes of an GSM\_HR RTP payload */}}
\DoxyCodeLine{19 \textcolor{preprocessor}{\#define GSM\_HR\_BYTES\_RTP\_RFC5993 (GSM\_HR\_BYTES + 1)}}
\DoxyCodeLine{20 \textcolor{preprocessor}{\#define GSM\_HR\_BYTES\_RTP\_TS101318 (GSM\_HR\_BYTES)}}
\DoxyCodeLine{21 }
\DoxyCodeLine{22 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm610\_bitorder[]; \textcolor{comment}{/* FR */}}
\DoxyCodeLine{23 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm620\_unvoiced\_bitorder[]; \textcolor{comment}{/* HR unvoiced */}}
\DoxyCodeLine{24 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm620\_voiced\_bitorder[];   \textcolor{comment}{/* HR voiced */}}
\DoxyCodeLine{25 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm660\_bitorder[]; \textcolor{comment}{/* EFR */}}
\DoxyCodeLine{26 }
\DoxyCodeLine{27 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_12\_2\_bitorder[];       \textcolor{comment}{/* AMR 12.2  kbits */}}
\DoxyCodeLine{28 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_10\_2\_bitorder[];       \textcolor{comment}{/* AMR 10.2  kbits */}}
\DoxyCodeLine{29 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_7\_95\_bitorder[];       \textcolor{comment}{/* AMR  7.95 kbits */}}
\DoxyCodeLine{30 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_7\_4\_bitorder[]; \textcolor{comment}{/* AMR  7.4  kbits */}}
\DoxyCodeLine{31 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_6\_7\_bitorder[]; \textcolor{comment}{/* AMR  6.7  kbits */}}
\DoxyCodeLine{32 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_5\_9\_bitorder[]; \textcolor{comment}{/* AMR  5.9  kbits */}}
\DoxyCodeLine{33 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_5\_15\_bitorder[];       \textcolor{comment}{/* AMR  5.15 kbits */}}
\DoxyCodeLine{34 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t gsm690\_4\_75\_bitorder[];       \textcolor{comment}{/* AMR  4.75 kbits */}}
\DoxyCodeLine{35 }
\DoxyCodeLine{36 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t osmo\_gsm611\_silence\_frame[GSM\_FR\_BYTES];}
\DoxyCodeLine{37 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t osmo\_gsm620\_silence\_frame[GSM\_HR\_BYTES];}
\DoxyCodeLine{38 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t osmo\_gsm620\_homing\_frame[GSM\_HR\_BYTES];}
\DoxyCodeLine{39 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t osmo\_gsm660\_homing\_frame[GSM\_EFR\_BYTES];}
\DoxyCodeLine{40 }
\DoxyCodeLine{41 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }value\_string osmo\_amr\_type\_names[];}
\DoxyCodeLine{42 }
\DoxyCodeLine{43 \textcolor{keyword}{enum} osmo\_amr\_type \{}
\DoxyCodeLine{44        AMR\_4\_75 = 0,}
\DoxyCodeLine{45        AMR\_5\_15 = 1,}
\DoxyCodeLine{46        AMR\_5\_90 = 2,}
\DoxyCodeLine{47        AMR\_6\_70 = 3,}
\DoxyCodeLine{48        AMR\_7\_40 = 4,}
\DoxyCodeLine{49        AMR\_7\_95 = 5,}
\DoxyCodeLine{50        AMR\_10\_2 = 6,}
\DoxyCodeLine{51        AMR\_12\_2 = 7,}
\DoxyCodeLine{52        AMR\_SID = 8,}
\DoxyCodeLine{53        AMR\_GSM\_EFR\_SID = 9,}
\DoxyCodeLine{54        AMR\_TDMA\_EFR\_SID = 10,}
\DoxyCodeLine{55        AMR\_PDC\_EFR\_SID = 11,}
\DoxyCodeLine{56        AMR\_NO\_DATA = 15,}
\DoxyCodeLine{57 \};}
\DoxyCodeLine{58 }
\DoxyCodeLine{59 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *osmo\_amr\_type\_name(\textcolor{keyword}{enum} osmo\_amr\_type type)}
\DoxyCodeLine{60 \{ \textcolor{keywordflow}{return} get\_value\_string(osmo\_amr\_type\_names, type); \}}
\DoxyCodeLine{61 }
\DoxyCodeLine{62 \textcolor{keyword}{enum} osmo\_amr\_quality \{}
\DoxyCodeLine{63        AMR\_BAD = 0,}
\DoxyCodeLine{64        AMR\_GOOD = 1}
\DoxyCodeLine{65 \};}
\DoxyCodeLine{66 }
\DoxyCodeLine{67 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t gsm690\_bitlength[AMR\_NO\_DATA+1];}
\DoxyCodeLine{68 }
\DoxyCodeLine{69 \textcolor{keywordtype}{int} osmo\_amr\_s\_to\_d(ubit\_t *out, \textcolor{keyword}{const} ubit\_t *in, uint16\_t n\_bits, \textcolor{keyword}{enum} osmo\_amr\_type amr\_mode);}
\DoxyCodeLine{70 \textcolor{keywordtype}{int} osmo\_amr\_d\_to\_s(ubit\_t *out, \textcolor{keyword}{const} ubit\_t *in, uint16\_t n\_bits, \textcolor{keyword}{enum} osmo\_amr\_type amr\_mode);}
\DoxyCodeLine{71 }
\DoxyCodeLine{76 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{bool} osmo\_amr\_is\_speech(\textcolor{keyword}{enum} osmo\_amr\_type ft)}
\DoxyCodeLine{77 \{}
\DoxyCodeLine{78         \textcolor{keywordflow}{switch} (ft) \{}
\DoxyCodeLine{79         \textcolor{keywordflow}{case} AMR\_4\_75:}
\DoxyCodeLine{80         \textcolor{keywordflow}{case} AMR\_5\_15:}
\DoxyCodeLine{81         \textcolor{keywordflow}{case} AMR\_5\_90:}
\DoxyCodeLine{82         \textcolor{keywordflow}{case} AMR\_6\_70:}
\DoxyCodeLine{83         \textcolor{keywordflow}{case} AMR\_7\_40:}
\DoxyCodeLine{84         \textcolor{keywordflow}{case} AMR\_7\_95:}
\DoxyCodeLine{85         \textcolor{keywordflow}{case} AMR\_10\_2:}
\DoxyCodeLine{86         \textcolor{keywordflow}{case} AMR\_12\_2:}
\DoxyCodeLine{87                 \textcolor{keywordflow}{return} \textcolor{keyword}{true};}
\DoxyCodeLine{88         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{89                 \textcolor{keywordflow}{return} \textcolor{keyword}{false};}
\DoxyCodeLine{90         \}}
\DoxyCodeLine{91 \}}
\DoxyCodeLine{92 }
\DoxyCodeLine{93 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t osmo\_amr\_sbits\_per\_mode[AMR\_NO\_DATA+1];}
\DoxyCodeLine{94 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint8\_t osmo\_amr\_params\_per\_mode[AMR\_NO\_DATA+1];}
\DoxyCodeLine{95 }
\DoxyCodeLine{96 \textcolor{keywordtype}{int} osmo\_amr\_param\_to\_sbits(ubit\_t *s\_bits, \textcolor{keyword}{const} uint16\_t *param,}
\DoxyCodeLine{97                                 \textcolor{keyword}{enum} osmo\_amr\_type mode);}
\DoxyCodeLine{98 \textcolor{keywordtype}{int} osmo\_amr\_sbits\_to\_param(uint16\_t *param, \textcolor{keyword}{const} ubit\_t *s\_bits,}
\DoxyCodeLine{99                                 \textcolor{keyword}{enum} osmo\_amr\_type mode);}
\DoxyCodeLine{100 }
\DoxyCodeLine{101 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_4\_75[];}
\DoxyCodeLine{102 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_5\_15[];}
\DoxyCodeLine{103 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_5\_90[];}
\DoxyCodeLine{104 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_6\_70[];}
\DoxyCodeLine{105 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_7\_40[];}
\DoxyCodeLine{106 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_7\_95[];}
\DoxyCodeLine{107 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_10\_2[];}
\DoxyCodeLine{108 \textcolor{keyword}{extern} \textcolor{keyword}{const} uint16\_t osmo\_amr\_dhf\_12\_2[];}
\DoxyCodeLine{109 }
\DoxyCodeLine{110 \textcolor{comment}{/* SID ternary classification per GSM 06.31 \& 06.81 section 6.1.1 */}}
\DoxyCodeLine{111 \textcolor{keyword}{enum} osmo\_gsm631\_sid\_class \{}
\DoxyCodeLine{112        OSMO\_GSM631\_SID\_CLASS\_SPEECH  = 0,}
\DoxyCodeLine{113        OSMO\_GSM631\_SID\_CLASS\_INVALID = 1,}
\DoxyCodeLine{114        OSMO\_GSM631\_SID\_CLASS\_VALID   = 2,}
\DoxyCodeLine{115 \};}
\DoxyCodeLine{116 }
\DoxyCodeLine{117 \textcolor{keywordtype}{bool} osmo\_fr\_check\_sid(\textcolor{keyword}{const} uint8\_t *rtp\_payload, \textcolor{keywordtype}{size\_t} payload\_len);}
\DoxyCodeLine{118 \textcolor{keywordtype}{bool} osmo\_hr\_check\_sid(\textcolor{keyword}{const} uint8\_t *rtp\_payload, \textcolor{keywordtype}{size\_t} payload\_len);}
\DoxyCodeLine{119 \textcolor{keywordtype}{bool} osmo\_efr\_check\_sid(\textcolor{keyword}{const} uint8\_t *rtp\_payload, \textcolor{keywordtype}{size\_t} payload\_len);}
\DoxyCodeLine{120 }
\DoxyCodeLine{121 \textcolor{keyword}{enum} osmo\_gsm631\_sid\_class osmo\_fr\_sid\_classify(\textcolor{keyword}{const} uint8\_t *rtp\_payload);}
\DoxyCodeLine{122 \textcolor{keyword}{enum} osmo\_gsm631\_sid\_class osmo\_efr\_sid\_classify(\textcolor{keyword}{const} uint8\_t *rtp\_payload);}
\DoxyCodeLine{123 \textcolor{keyword}{enum} osmo\_gsm631\_sid\_class osmo\_hr\_sid\_classify(\textcolor{keyword}{const} uint8\_t *rtp\_payload,}
\DoxyCodeLine{124                                                 \textcolor{keywordtype}{bool} bci\_flag,}
\DoxyCodeLine{125                                                 \textcolor{keywordtype}{bool} *bfi\_from\_bci);}
\DoxyCodeLine{126 }
\DoxyCodeLine{132 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{bool} osmo\_fr\_is\_any\_sid(\textcolor{keyword}{const} uint8\_t *rtp\_payload)}
\DoxyCodeLine{133 \{}
\DoxyCodeLine{134         \textcolor{keyword}{enum} osmo\_gsm631\_sid\_class sidc;}
\DoxyCodeLine{135 }
\DoxyCodeLine{136         sidc = osmo\_fr\_sid\_classify(rtp\_payload);}
\DoxyCodeLine{137         \textcolor{keywordflow}{return} sidc != OSMO\_GSM631\_SID\_CLASS\_SPEECH;}
\DoxyCodeLine{138 \}}
\DoxyCodeLine{139 }
\DoxyCodeLine{145 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{bool} osmo\_efr\_is\_any\_sid(\textcolor{keyword}{const} uint8\_t *rtp\_payload)}
\DoxyCodeLine{146 \{}
\DoxyCodeLine{147         \textcolor{keyword}{enum} osmo\_gsm631\_sid\_class sidc;}
\DoxyCodeLine{148 }
\DoxyCodeLine{149         sidc = osmo\_efr\_sid\_classify(rtp\_payload);}
\DoxyCodeLine{150         \textcolor{keywordflow}{return} sidc != OSMO\_GSM631\_SID\_CLASS\_SPEECH;}
\DoxyCodeLine{151 \}}
\DoxyCodeLine{152 }
\DoxyCodeLine{153 \textcolor{keywordtype}{bool} osmo\_fr\_sid\_preen(uint8\_t *rtp\_payload);}
\DoxyCodeLine{154 \textcolor{keywordtype}{bool} osmo\_efr\_sid\_preen(uint8\_t *rtp\_payload);}
\DoxyCodeLine{155 }
\DoxyCodeLine{156 \textcolor{keywordtype}{void} osmo\_fr\_sid\_reset(uint8\_t *rtp\_payload);}
\DoxyCodeLine{157 \textcolor{keywordtype}{void} osmo\_hr\_sid\_reset(uint8\_t *rtp\_payload);}
\DoxyCodeLine{158 \textcolor{keywordtype}{void} osmo\_efr\_sid\_reset(uint8\_t *rtp\_payload);}
\DoxyCodeLine{159 }
\DoxyCodeLine{160 \textcolor{keywordtype}{int} osmo\_amr\_rtp\_enc(uint8\_t *payload, uint8\_t cmr, \textcolor{keyword}{enum} osmo\_amr\_type ft,}
\DoxyCodeLine{161                      \textcolor{keyword}{enum} osmo\_amr\_quality bfi);}
\DoxyCodeLine{162 \textcolor{keywordtype}{int} osmo\_amr\_rtp\_dec(\textcolor{keyword}{const} uint8\_t *payload, \textcolor{keywordtype}{int} payload\_len, uint8\_t *cmr,}
\DoxyCodeLine{163                      int8\_t *cmi, \textcolor{keyword}{enum} osmo\_amr\_type *ft,}
\DoxyCodeLine{164                      \textcolor{keyword}{enum} osmo\_amr\_quality *bfi, int8\_t *sti);}

\end{DoxyCode}
