\doxysection{src/codec/gsm610.c File Reference}
\label{gsm610_8c}\index{src/codec/gsm610.c@{src/codec/gsm610.c}}


GSM 06.\+10 -\/ GSM FR codec.  


{\ttfamily \#include $<$stdint.\+h$>$}\newline
{\ttfamily \#include $<$stdbool.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/bitvec.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/codec/codec.\+h$>$}\newline
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
bool \textbf{ osmo\+\_\+fr\+\_\+check\+\_\+sid} (const uint8\+\_\+t $\ast$rtp\+\_\+payload, size\+\_\+t payload\+\_\+len)
\begin{DoxyCompactList}\small\item\em Check whether RTP frame contains FR SID code word according to TS 101 318 §5.1.\+2. \end{DoxyCompactList}\item 
enum \textbf{ osmo\+\_\+gsm631\+\_\+sid\+\_\+class} \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+classify} (const uint8\+\_\+t $\ast$rtp\+\_\+payload)
\begin{DoxyCompactList}\small\item\em Classify potentially-\/\+SID FR codec frame in RTP format according to the rules of GSM 06.\+31 §6.1.\+1. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+reset} (uint8\+\_\+t $\ast$rtp\+\_\+payload)
\begin{DoxyCompactList}\small\item\em Reset the SID field and the unused bits of a potentially corrupted, but still valid GSM-\/\+FR SID frame in RTP encoding to their pristine state. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+preen} (uint8\+\_\+t $\ast$rtp\+\_\+payload)
\begin{DoxyCompactList}\small\item\em Preen potentially-\/\+SID FR codec frame in RTP format, ensuring that it is either a speech frame or a valid SID, and if the latter, making it a perfect, error-\/free SID frame. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
const uint16\+\_\+t \textbf{ gsm610\+\_\+bitorder} [260]
\item 
const uint8\+\_\+t \textbf{ osmo\+\_\+gsm611\+\_\+silence\+\_\+frame} [\textbf{ GSM\+\_\+\+FR\+\_\+\+BYTES}]
\item 
static const uint16\+\_\+t \textbf{ sid\+\_\+code\+\_\+word\+\_\+bits} [95]
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
GSM 06.\+10 -\/ GSM FR codec. 



\doxysubsection{Function Documentation}
\mbox{\label{gsm610_8c_a20ec1df6610a428b6faadac2ccff0faf}} 
\index{gsm610.c@{gsm610.c}!osmo\_fr\_check\_sid@{osmo\_fr\_check\_sid}}
\index{osmo\_fr\_check\_sid@{osmo\_fr\_check\_sid}!gsm610.c@{gsm610.c}}
\doxysubsubsection{osmo\_fr\_check\_sid()}
{\footnotesize\ttfamily bool osmo\+\_\+fr\+\_\+check\+\_\+sid (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{rtp\+\_\+payload,  }\item[{size\+\_\+t}]{payload\+\_\+len }\end{DoxyParamCaption})}



Check whether RTP frame contains FR SID code word according to TS 101 318 §5.1.\+2. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rtp\+\_\+payload} & Buffer with RTP payload \\
\hline
\mbox{\texttt{ in}}  & {\em payload\+\_\+len} & Length of payload \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if code word is found, false otherwise 
\end{DoxyReturn}


References \textbf{ ARRAY\+\_\+\+SIZE}, \textbf{ bitvec\+\_\+get\+\_\+bit\+\_\+pos()}, \textbf{ bitvec\+::data}, \textbf{ bitvec\+::data\+\_\+len}, \textbf{ sid\+\_\+code\+\_\+word\+\_\+bits}, and \textbf{ ZERO}.



Referenced by \textbf{ conceal\+\_\+frame()}.

\mbox{\label{gsm610_8c_a7d88af998487b2b71d10ea0a6fa6fe07}} 
\index{gsm610.c@{gsm610.c}!osmo\_fr\_sid\_classify@{osmo\_fr\_sid\_classify}}
\index{osmo\_fr\_sid\_classify@{osmo\_fr\_sid\_classify}!gsm610.c@{gsm610.c}}
\doxysubsubsection{osmo\_fr\_sid\_classify()}
{\footnotesize\ttfamily enum \textbf{ osmo\+\_\+gsm631\+\_\+sid\+\_\+class} osmo\+\_\+fr\+\_\+sid\+\_\+classify (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{rtp\+\_\+payload }\end{DoxyParamCaption})}



Classify potentially-\/\+SID FR codec frame in RTP format according to the rules of GSM 06.\+31 §6.1.\+1. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rtp\+\_\+payload} & Buffer with RTP payload \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
enum osmo\+\_\+gsm631\+\_\+sid\+\_\+class, with symbolic values OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+SPEECH, OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+INVALID or OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+VALID corresponding to the 3 possible bit-\/counting classifications prescribed by the spec.
\end{DoxyReturn}
Differences between the more familiar \doxyref{osmo\+\_\+fr\+\_\+check\+\_\+sid()}{p.}{gsm610_8c_a20ec1df6610a428b6faadac2ccff0faf} and the present function are\+:


\begin{DoxyEnumerate}
\item \doxyref{osmo\+\_\+fr\+\_\+check\+\_\+sid()}{p.}{gsm610_8c_a20ec1df6610a428b6faadac2ccff0faf} returns true only if the SID frame is absolutely perfect, with all 95 bits of the SID code word zeroed. However, the rules of GSM 06.\+31 §6.1.\+1 allow up to one bit to be in error, and the frame is still accepted as valid SID.
\item The third possible state of invalid SID is not handled at all by the simpler \doxyref{osmo\+\_\+fr\+\_\+check\+\_\+sid()}{p.}{gsm610_8c_a20ec1df6610a428b6faadac2ccff0faf} function.
\item \doxyref{osmo\+\_\+fr\+\_\+check\+\_\+sid()}{p.}{gsm610_8c_a20ec1df6610a428b6faadac2ccff0faf} includes a check for 0xD RTP signature, and returns false if that signature nibble is wrong. That check is not included in the present version because there is no place for it in the ETSI-\/prescribed classification, it is neither speech nor SID. The assumption is that this function is used to classify the bit content of received codec frames, not their RTP encoding -\/ the latter needs to be validated beforehand.
\end{DoxyEnumerate}

Which function should one use? The answer depends on the specific circumstances, and needs to be addressed on a case-\/by-\/case basis. 

References \textbf{ ARRAY\+\_\+\+SIZE}, \textbf{ bitvec\+\_\+get\+\_\+bit\+\_\+pos()}, \textbf{ bitvec\+::data}, \textbf{ bitvec\+::data\+\_\+len}, \textbf{ GSM\+\_\+\+FR\+\_\+\+BYTES}, \textbf{ n}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+INVALID}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+SPEECH}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+VALID}, \textbf{ sid\+\_\+code\+\_\+word\+\_\+bits}, and \textbf{ ZERO}.



Referenced by \textbf{ fr\+\_\+ecu\+\_\+input()}, \textbf{ osmo\+\_\+fr\+\_\+is\+\_\+any\+\_\+sid()}, and \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+preen()}.

\mbox{\label{gsm610_8c_a22c81d44e6b5ebeec19fb33aace3f214}} 
\index{gsm610.c@{gsm610.c}!osmo\_fr\_sid\_preen@{osmo\_fr\_sid\_preen}}
\index{osmo\_fr\_sid\_preen@{osmo\_fr\_sid\_preen}!gsm610.c@{gsm610.c}}
\doxysubsubsection{osmo\_fr\_sid\_preen()}
{\footnotesize\ttfamily bool osmo\+\_\+fr\+\_\+sid\+\_\+preen (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{rtp\+\_\+payload }\end{DoxyParamCaption})}



Preen potentially-\/\+SID FR codec frame in RTP format, ensuring that it is either a speech frame or a valid SID, and if the latter, making it a perfect, error-\/free SID frame. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rtp\+\_\+payload} & Buffer with RTP payload -\/ must be writable! \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if the frame is good, false otherwise 
\end{DoxyReturn}


References \textbf{ OSMO\+\_\+\+ASSERT}, \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+classify()}, \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+reset()}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+INVALID}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+SPEECH}, and \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+VALID}.

\mbox{\label{gsm610_8c_a9a5cdba9e2924cdb1613a4ed8aa2a6a3}} 
\index{gsm610.c@{gsm610.c}!osmo\_fr\_sid\_reset@{osmo\_fr\_sid\_reset}}
\index{osmo\_fr\_sid\_reset@{osmo\_fr\_sid\_reset}!gsm610.c@{gsm610.c}}
\doxysubsubsection{osmo\_fr\_sid\_reset()}
{\footnotesize\ttfamily void osmo\+\_\+fr\+\_\+sid\+\_\+reset (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{rtp\+\_\+payload }\end{DoxyParamCaption})}



Reset the SID field and the unused bits of a potentially corrupted, but still valid GSM-\/\+FR SID frame in RTP encoding to their pristine state. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rtp\+\_\+payload} & Buffer with RTP payload -\/ must be writable!\\
\hline
\end{DoxyParams}
Per GSM 06.\+12 section 5.\+2, a freshly minted SID frame carries 60 bits of comfort noise parameters (LARc and 4 times Xmaxc), while the remaining 200 bits are all zeros; the latter 200 all-\/0 bits further break down into 95 bits of SID field (checked by receivers to detect SID) and 105 unused bits which receivers are told to ignore. Network elements that receive SID frames from call leg A uplink and need to retransmit them on leg B downlink should \char`\"{}rejuvenate\char`\"{} received SID frames prior to retransmission; this function does the job. 

Referenced by \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+preen()}.



\doxysubsection{Variable Documentation}
\mbox{\label{gsm610_8c_a3234200b8a977081226c41686b69f0ad}} 
\index{gsm610.c@{gsm610.c}!gsm610\_bitorder@{gsm610\_bitorder}}
\index{gsm610\_bitorder@{gsm610\_bitorder}!gsm610.c@{gsm610.c}}
\doxysubsubsection{gsm610\_bitorder}
{\footnotesize\ttfamily const uint16\+\_\+t gsm610\+\_\+bitorder[260]}

\mbox{\label{gsm610_8c_a66bd8670d5a45cc42022e58024f8aa3d}} 
\index{gsm610.c@{gsm610.c}!osmo\_gsm611\_silence\_frame@{osmo\_gsm611\_silence\_frame}}
\index{osmo\_gsm611\_silence\_frame@{osmo\_gsm611\_silence\_frame}!gsm610.c@{gsm610.c}}
\doxysubsubsection{osmo\_gsm611\_silence\_frame}
{\footnotesize\ttfamily const uint8\+\_\+t osmo\+\_\+gsm611\+\_\+silence\+\_\+frame[\textbf{ GSM\+\_\+\+FR\+\_\+\+BYTES}]}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{= \{}
\DoxyCodeLine{        0xDA, 0xA7, 0xAA, 0xA5, 0x1A,}
\DoxyCodeLine{        0x50, 0x20, 0x38, 0xE4, 0x6D, 0xB9, 0x1B,}
\DoxyCodeLine{        0x50, 0x20, 0x38, 0xE4, 0x6D, 0xB9, 0x1B,}
\DoxyCodeLine{        0x50, 0x20, 0x38, 0xE4, 0x6D, 0xB9, 0x1B,}
\DoxyCodeLine{        0x50, 0x20, 0x38, 0xE4, 0x6D, 0xB9, 0x1B,}
\DoxyCodeLine{\}}

\end{DoxyCode}


Referenced by \textbf{ fr\+\_\+ecu\+\_\+output()}.

\mbox{\label{gsm610_8c_a6c8dfb31eda086b9081045e642c4a1aa}} 
\index{gsm610.c@{gsm610.c}!sid\_code\_word\_bits@{sid\_code\_word\_bits}}
\index{sid\_code\_word\_bits@{sid\_code\_word\_bits}!gsm610.c@{gsm610.c}}
\doxysubsubsection{sid\_code\_word\_bits}
{\footnotesize\ttfamily const uint16\+\_\+t sid\+\_\+code\+\_\+word\+\_\+bits[95]\hspace{0.3cm}{\ttfamily [static]}}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{= \{}
\DoxyCodeLine{        }
\DoxyCodeLine{        57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 72, 73,}
\DoxyCodeLine{        75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91,}
\DoxyCodeLine{        93, 94, 113, 114, 116, 117, 119, 120, 122, 123,}
\DoxyCodeLine{        125, 126, 128, 129, 131, 132, 134, 135, 137,}
\DoxyCodeLine{        138, 140, 141, 143, 144, 146, 147, 149, 150,}
\DoxyCodeLine{        169, 170, 172, 173, 175, 176, 178, 179, 181,}
\DoxyCodeLine{        182, 184, 185, 187, 188, 190, 191, 193, 194,}
\DoxyCodeLine{        196, 197, 199, 200, 202, 203, 205, 206, 225,}
\DoxyCodeLine{        226, 228, 229, 231, 232, 234, 235, 237, 240,}
\DoxyCodeLine{        243, 246, 249, 252, 255, 258, 261}
\DoxyCodeLine{\}}

\end{DoxyCode}


Referenced by \textbf{ osmo\+\_\+fr\+\_\+check\+\_\+sid()}, and \textbf{ osmo\+\_\+fr\+\_\+sid\+\_\+classify()}.

