2021-10-26 03:34:27 +08:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv = "Content-Type" content = "text/xhtml;charset=UTF-8" / >
< meta http-equiv = "X-UA-Compatible" content = "IE=11" / >
2022-06-08 02:13:03 +08:00
< meta name = "generator" content = "Doxygen 1.9.4" / >
2021-10-26 03:34:27 +08:00
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< title > Algorithms_in_C: audio/alaw.c File Reference< / title >
< link href = "../../tabs.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../jquery.js" > < / script >
< script type = "text/javascript" src = "../../dynsections.js" > < / script >
< link href = "../../navtree.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../resize.js" > < / script >
< script type = "text/javascript" src = "../../navtreedata.js" > < / script >
< script type = "text/javascript" src = "../../navtree.js" > < / script >
< link href = "../../search/search.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "../../search/searchdata.js" > < / script >
< script type = "text/javascript" src = "../../search/search.js" > < / script >
< script type = "text/x-mathjax-config" >
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
< / script >
< script type = "text/javascript" async = "async" src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js" > < / script >
< link href = "../../doxygen.css" rel = "stylesheet" type = "text/css" / >
< / head >
< body >
< div id = "top" > <!-- do not remove this div, it is closed by doxygen! -->
< div id = "titlearea" >
< table cellspacing = "0" cellpadding = "0" >
< tbody >
2022-01-15 04:11:27 +08:00
< tr id = "projectrow" >
< td id = "projectalign" >
2021-10-26 03:34:27 +08:00
< div id = "projectname" > Algorithms_in_C< span id = "projectnumber" >   1.0.0< / span >
< / div >
< div id = "projectbrief" > Set of algorithms implemented in C.< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2022-06-08 02:13:03 +08:00
<!-- Generated by Doxygen 1.9.4 -->
2021-10-26 03:34:27 +08:00
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
/* @license-end */
< / script >
< script type = "text/javascript" src = "../../menudata.js" > < / script >
< script type = "text/javascript" src = "../../menu.js" > < / script >
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
< / script >
< div id = "main-nav" > < / div >
< / div > <!-- top -->
< div id = "side-nav" class = "ui-resizable side-nav-resizable" >
< div id = "nav-tree" >
< div id = "nav-tree-contents" >
< div id = "nav-sync" class = "sync" > < / div >
< / div >
< / div >
< div id = "splitbar" style = "-moz-user-select:none;"
class="ui-resizable-handle">
< / div >
< / div >
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
$(document).ready(function(){initNavTree('df/d27/alaw_8c.html','../../'); initResizable(); });
/* @license-end */
< / script >
< div id = "doc-content" >
<!-- window showing the filter options -->
< div id = "MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
< / div >
<!-- iframe showing the search results (closed by default) -->
< div id = "MSearchResultsWindow" >
< iframe src = "javascript:void(0)" frameborder = "0"
name="MSearchResults" id="MSearchResults">
< / iframe >
< / div >
< div class = "header" >
< div class = "summary" >
< a href = "#define-members" > Macros< / a > |
< a href = "#func-members" > Functions< / a > |
< a href = "#var-members" > Variables< / a > < / div >
< div class = "headertitle" > < div class = "title" > alaw.c File Reference< / div > < / div >
< / div > <!-- header -->
< div class = "contents" >
< p > A-law algorithm for encoding and decoding (16bit pcm < => a-law). This is the implementation of < a href = "https://en.wikipedia.org/wiki/G.711" target = "_blank" > G.711< / a > in C.
< a href = "#details" > More...< / a > < / p >
< div class = "textblock" > < code > #include < assert.h> < / code > < br / >
< code > #include < inttypes.h> < / code > < br / >
< code > #include < stdio.h> < / code > < br / >
< / div > < div class = "textblock" > < div class = "dynheader" >
Include dependency graph for alaw.c:< / div >
< div class = "dyncontent" >
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../da/d0b/alaw_8c__incl.svg" width = "270" height = "112" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
< / div > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "define-members" name = "define-members" > < / a >
Macros< / h2 > < / td > < / tr >
< tr class = "memitem:a05b49c662c073f89e86804f7856622a0" > < td class = "memItemLeft" align = "right" valign = "top" > #define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a >       ((size_t)8)< / td > < / tr >
< tr class = "memdesc:a05b49c662c073f89e86804f7856622a0" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Linear input code | Compressed code | Linear output code ---------------— +--------------— +----------------— s0000000abcdx | s000abcd | s0000000abcd1 s0000001abcdx | s001abcd | s0000001abcd1 s000001abcdxx | s010abcd | s000001abcd10 s00001abcdxxx | s011abcd | s00001abcd100 s0001abcdxxxx | s100abcd | s0001abcd1000 s001abcdxxxxx | s101abcd | s001abcd10000 s01abcdxxxxxx | s110abcd | s01abcd100000 s1abcdxxxxxxx | s111abcd | s1abcd1000000. < a href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a05b49c662c073f89e86804f7856622a0" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "func-members" name = "func-members" > < / a >
Functions< / h2 > < / td > < / tr >
< tr class = "memitem:a751d8e2c1975706e4d876316518c54c4" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../df/d27/alaw_8c.html#a751d8e2c1975706e4d876316518c54c4" > encode< / a > (uint8_t *out, int16_t *in, size_t len)< / td > < / tr >
< tr class = "memdesc:a751d8e2c1975706e4d876316518c54c4" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > 16bit pcm to 8bit alaw < a href = "../../df/d27/alaw_8c.html#a751d8e2c1975706e4d876316518c54c4" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a751d8e2c1975706e4d876316518c54c4" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a093ac72124e3c2268d1150676e63175d" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../df/d27/alaw_8c.html#a093ac72124e3c2268d1150676e63175d" > decode< / a > (int16_t *out, uint8_t *in, size_t len)< / td > < / tr >
< tr class = "memdesc:a093ac72124e3c2268d1150676e63175d" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > 8bit alaw to 16bit pcm < a href = "../../df/d27/alaw_8c.html#a093ac72124e3c2268d1150676e63175d" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a093ac72124e3c2268d1150676e63175d" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a840bf13d2e4d75d38fb7bf3a655152f5" > < td class = "memItemLeft" align = "right" valign = "top" > static void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../df/d27/alaw_8c.html#a840bf13d2e4d75d38fb7bf3a655152f5" > test< / a > (int16_t *pcm, uint8_t *coded, int16_t *decoded, size_t len)< / td > < / tr >
< tr class = "memdesc:a840bf13d2e4d75d38fb7bf3a655152f5" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Self-test implementations. < a href = "../../df/d27/alaw_8c.html#a840bf13d2e4d75d38fb7bf3a655152f5" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a840bf13d2e4d75d38fb7bf3a655152f5" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a0ddf1224851353fc92bfbff6f499fa97" > < td class = "memItemLeft" align = "right" valign = "top" > int  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../df/d27/alaw_8c.html#a0ddf1224851353fc92bfbff6f499fa97" > main< / a > (int argc, char *argv[])< / td > < / tr >
< tr class = "memdesc:a0ddf1224851353fc92bfbff6f499fa97" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Main function. < a href = "../../df/d27/alaw_8c.html#a0ddf1224851353fc92bfbff6f499fa97" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a0ddf1224851353fc92bfbff6f499fa97" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "var-members" name = "var-members" > < / a >
Variables< / h2 > < / td > < / tr >
< tr class = "memitem:a538629d6e89d6bd943c5853b8aad4546" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a538629d6e89d6bd943c5853b8aad4546" name = "a538629d6e89d6bd943c5853b8aad4546" > < / a >
int16_t  < / td > < td class = "memItemRight" valign = "bottom" > < b > pcm< / b > [< a class = "el" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ] = {1000, -1000, 1234, 3200, -1314, 0, 32767, -32768}< / td > < / tr >
< tr class = "separator:a538629d6e89d6bd943c5853b8aad4546" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a462175be15495bb589d91d3b9bfca266" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a462175be15495bb589d91d3b9bfca266" name = "a462175be15495bb589d91d3b9bfca266" > < / a >
uint8_t  < / td > < td class = "memItemRight" valign = "bottom" > < b > r_coded< / b > [< a class = "el" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ] = {250, 122, 230, 156, 97, 213, 170, 42}< / td > < / tr >
< tr class = "separator:a462175be15495bb589d91d3b9bfca266" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a2df278be294207b289568c46f14d18b3" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a2df278be294207b289568c46f14d18b3" name = "a2df278be294207b289568c46f14d18b3" > < / a >
int16_t  < / td > < td class = "memItemRight" valign = "bottom" > < b > r_decoded< / b > [< a class = "el" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ] = {1008, -1008, 1248, 3264, -1312, 8, 32256, -32256}< / td > < / tr >
< tr class = "separator:a2df278be294207b289568c46f14d18b3" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
< div class = "textblock" > < p > A-law algorithm for encoding and decoding (16bit pcm < => a-law). This is the implementation of < a href = "https://en.wikipedia.org/wiki/G.711" target = "_blank" > G.711< / a > in C. < / p >
< dl class = "section author" > < dt > Author< / dt > < dd > < a href = "https://github.com/HiSunzhenliang" target = "_blank" > sunzhenliang< / a > < / dd > < / dl >
< / div > < h2 class = "groupheader" > Macro Definition Documentation< / h2 >
< a id = "a05b49c662c073f89e86804f7856622a0" name = "a05b49c662c073f89e86804f7856622a0" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a05b49c662c073f89e86804f7856622a0" > ◆ < / a > < / span > LEN< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > #define LEN      ((size_t)8)< / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Linear input code | Compressed code | Linear output code ---------------— +--------------— +----------------— s0000000abcdx | s000abcd | s0000000abcd1 s0000001abcdx | s001abcd | s0000001abcd1 s000001abcdxx | s010abcd | s000001abcd10 s00001abcdxxx | s011abcd | s00001abcd100 s0001abcdxxxx | s100abcd | s0001abcd1000 s001abcdxxxxx | s101abcd | s001abcd10000 s01abcdxxxxxx | s110abcd | s01abcd100000 s1abcdxxxxxxx | s111abcd | s1abcd1000000. < / p >
< p > Compressed code: (s | eee | abcd) for assert for appropriate size int types for IO operations < / p >
< / div >
< / div >
< h2 class = "groupheader" > Function Documentation< / h2 >
< a id = "a093ac72124e3c2268d1150676e63175d" name = "a093ac72124e3c2268d1150676e63175d" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a093ac72124e3c2268d1150676e63175d" > ◆ < / a > < / span > decode()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void decode < / td >
< td > (< / td >
< td class = "paramtype" > int16_t *  < / td >
< td class = "paramname" > < em > out< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > uint8_t *  < / td >
< td class = "paramname" > < em > in< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > size_t  < / td >
< td class = "paramname" > < em > len< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > 8bit alaw to 16bit pcm < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramname" > out< / td > < td > signed 16bit pcm array < / td > < / tr >
< tr > < td class = "paramname" > in< / td > < td > unsigned 8bit alaw array < / td > < / tr >
< tr > < td class = "paramname" > len< / td > < td > length of alaw array < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > void < / dd > < / dl >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 108< / span > {< / div >
< div class = "line" > < span class = "lineno" > 109< / span > uint8_t alaw = 0;< / div >
< div class = "line" > < span class = "lineno" > 110< / span > int32_t pcm = 0;< / div >
< div class = "line" > < span class = "lineno" > 111< / span > int32_t sign = 0;< / div >
< div class = "line" > < span class = "lineno" > 112< / span > int32_t eee = 0;< / div >
< div class = "line" > < span class = "lineno" > 113< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < len; i++)< / div >
< div class = "line" > < span class = "lineno" > 114< / span > {< / div >
< div class = "line" > < span class = "lineno" > 115< / span > alaw = *in++;< / div >
< div class = "line" > < span class = "lineno" > 116< / span > < / div >
< div class = "line" > < span class = "lineno" > 117< / span > < span class = "comment" > /* Re-toggle toggled bits */< / span > < / div >
< div class = "line" > < span class = "lineno" > 118< / span > alaw ^= 0xD5;< / div >
< div class = "line" > < span class = "lineno" > 119< / span > < / div >
< div class = "line" > < span class = "lineno" > 120< / span > < span class = "comment" > /* Get sign bit */< / span > < / div >
< div class = "line" > < span class = "lineno" > 121< / span > sign = alaw & 0x80;< / div >
< div class = "line" > < span class = "lineno" > 122< / span > < / div >
< div class = "line" > < span class = "lineno" > 123< / span > < span class = "comment" > /* Get eee bits */< / span > < / div >
< div class = "line" > < span class = "lineno" > 124< / span > eee = (alaw & 0x70) > > 4;< / div >
< div class = "line" > < span class = "lineno" > 125< / span > < / div >
< div class = "line" > < span class = "lineno" > 126< / span > < span class = "comment" > /* Get abcd bits and add 1/2 quantization step */< / span > < / div >
< div class = "line" > < span class = "lineno" > 127< / span > pcm = (alaw & 0x0f) < < 4 | 8;< / div >
< div class = "line" > < span class = "lineno" > 128< / span > < / div >
< div class = "line" > < span class = "lineno" > 129< / span > < span class = "comment" > /* If quantization level > 0, there need `1` bit before abcd bits */< / span > < / div >
< div class = "line" > < span class = "lineno" > 130< / span > pcm += eee ? 0x100 : 0x0;< / div >
< div class = "line" > < span class = "lineno" > 131< / span > < / div >
< div class = "line" > < span class = "lineno" > 132< / span > < span class = "comment" > /* Left shift according quantization level */< / span > < / div >
< div class = "line" > < span class = "lineno" > 133< / span > pcm < < = eee > 1 ? (eee - 1) : 0;< / div >
< div class = "line" > < span class = "lineno" > 134< / span > < / div >
< div class = "line" > < span class = "lineno" > 135< / span > < span class = "comment" > /* Use the right sign */< / span > < / div >
< div class = "line" > < span class = "lineno" > 136< / span > *out++ = sign ? -pcm : pcm;< / div >
< div class = "line" > < span class = "lineno" > 137< / span > }< / div >
< div class = "line" > < span class = "lineno" > 138< / span > }< / div >
2021-10-26 03:34:27 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "a751d8e2c1975706e4d876316518c54c4" name = "a751d8e2c1975706e4d876316518c54c4" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a751d8e2c1975706e4d876316518c54c4" > ◆ < / a > < / span > encode()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void encode < / td >
< td > (< / td >
< td class = "paramtype" > uint8_t *  < / td >
< td class = "paramname" > < em > out< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int16_t *  < / td >
< td class = "paramname" > < em > in< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > size_t  < / td >
< td class = "paramname" > < em > len< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > 16bit pcm to 8bit alaw < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramname" > out< / td > < td > unsigned 8bit alaw array < / td > < / tr >
< tr > < td class = "paramname" > in< / td > < td > signed 16bit pcm array < / td > < / tr >
< tr > < td class = "paramname" > len< / td > < td > length of pcm array < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > void < / dd > < / dl >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 47< / span > {< / div >
< div class = "line" > < span class = "lineno" > 48< / span > uint8_t alaw = 0;< / div >
< div class = "line" > < span class = "lineno" > 49< / span > int16_t pcm = 0;< / div >
< div class = "line" > < span class = "lineno" > 50< / span > int32_t sign = 0;< / div >
< div class = "line" > < span class = "lineno" > 51< / span > int32_t abcd = 0;< / div >
< div class = "line" > < span class = "lineno" > 52< / span > int32_t eee = 0;< / div >
< div class = "line" > < span class = "lineno" > 53< / span > int32_t mask = 0;< / div >
< div class = "line" > < span class = "lineno" > 54< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < len; i++)< / div >
< div class = "line" > < span class = "lineno" > 55< / span > {< / div >
< div class = "line" > < span class = "lineno" > 56< / span > pcm = *in++;< / div >
< div class = "line" > < span class = "lineno" > 57< / span > < span class = "comment" > /* 0-7 kinds of quantization level from the table above */< / span > < / div >
< div class = "line" > < span class = "lineno" > 58< / span > eee = 7;< / div >
< div class = "line" > < span class = "lineno" > 59< / span > mask = 0x4000; < span class = "comment" > /* 0x4000: ' 0b0100 0000 0000 0000' */< / span > < / div >
< div class = "line" > < span class = "lineno" > 60< / span > < / div >
< div class = "line" > < span class = "lineno" > 61< / span > < span class = "comment" > /* Get sign bit */< / span > < / div >
< div class = "line" > < span class = "lineno" > 62< / span > sign = (pcm & 0x8000) > > 8;< / div >
< div class = "line" > < span class = "lineno" > 63< / span > < / div >
< div class = "line" > < span class = "lineno" > 64< / span > < span class = "comment" > /* Turn negative pcm to positive */< / span > < / div >
< div class = "line" > < span class = "lineno" > 65< / span > < span class = "comment" > /* The absolute value of a negative number may be larger than the size< / span > < / div >
< div class = "line" > < span class = "lineno" > 66< / span > < span class = "comment" > * of the corresponding positive number, so here needs `-pcm -1` after< / span > < / div >
< div class = "line" > < span class = "lineno" > 67< / span > < span class = "comment" > * taking the opposite number. */< / span > < / div >
< div class = "line" > < span class = "lineno" > 68< / span > pcm = sign ? (-pcm - 1) : pcm;< / div >
< div class = "line" > < span class = "lineno" > 69< / span > < / div >
< div class = "line" > < span class = "lineno" > 70< / span > < span class = "comment" > /* Get eee and abcd bit */< / span > < / div >
< div class = "line" > < span class = "lineno" > 71< / span > < span class = "comment" > /* Use mask to locate the first `1` bit and quantization level at the< / span > < / div >
< div class = "line" > < span class = "lineno" > 72< / span > < span class = "comment" > * same time */< / span > < / div >
< div class = "line" > < span class = "lineno" > 73< / span > < span class = "keywordflow" > while< / span > ((pcm & mask) == 0 & & eee > 0)< / div >
< div class = "line" > < span class = "lineno" > 74< / span > {< / div >
< div class = "line" > < span class = "lineno" > 75< / span > eee--;< / div >
< div class = "line" > < span class = "lineno" > 76< / span > mask > > = 1;< / div >
< div class = "line" > < span class = "lineno" > 77< / span > }< / div >
< div class = "line" > < span class = "lineno" > 78< / span > < / div >
< div class = "line" > < span class = "lineno" > 79< / span > < span class = "comment" > /* The location of abcd bits is related with quantization level. Check< / span > < / div >
< div class = "line" > < span class = "lineno" > 80< / span > < span class = "comment" > * the table above to determine how many bits to `> > ` to get abcd */< / span > < / div >
< div class = "line" > < span class = "lineno" > 81< / span > abcd = (pcm > > (eee ? (eee + 3) : 4)) & 0x0f;< / div >
< div class = "line" > < span class = "lineno" > 82< / span > < / div >
< div class = "line" > < span class = "lineno" > 83< / span > < span class = "comment" > /* Put the quantization level number at right bit location to get eee< / span > < / div >
< div class = "line" > < span class = "lineno" > 84< / span > < span class = "comment" > * bits */< / span > < / div >
< div class = "line" > < span class = "lineno" > 85< / span > eee < < = 4;< / div >
< div class = "line" > < span class = "lineno" > 86< / span > < / div >
< div class = "line" > < span class = "lineno" > 87< / span > < span class = "comment" > /* Splice results */< / span > < / div >
< div class = "line" > < span class = "lineno" > 88< / span > alaw = (sign | eee | abcd);< / div >
< div class = "line" > < span class = "lineno" > 89< / span > < / div >
< div class = "line" > < span class = "lineno" > 90< / span > < span class = "comment" > /* The standard specifies that all resulting even bits (LSB< / span > < / div >
< div class = "line" > < span class = "lineno" > 91< / span > < span class = "comment" > * is even) are inverted before the octet is transmitted. This is to< / span > < / div >
< div class = "line" > < span class = "lineno" > 92< / span > < span class = "comment" > * provide plenty of 0/1 transitions to facilitate the clock recovery< / span > < / div >
< div class = "line" > < span class = "lineno" > 93< / span > < span class = "comment" > * process in the PCM receivers. Thus, a silent A-law encoded PCM< / span > < / div >
< div class = "line" > < span class = "lineno" > 94< / span > < span class = "comment" > * channel has the 8 bit samples coded 0xD5 instead of 0x80 in the< / span > < / div >
< div class = "line" > < span class = "lineno" > 95< / span > < span class = "comment" > * octets. (Reference from wiki above) */< / span > < / div >
< div class = "line" > < span class = "lineno" > 96< / span > *out++ = alaw ^ 0xD5;< / div >
< div class = "line" > < span class = "lineno" > 97< / span > }< / div >
< div class = "line" > < span class = "lineno" > 98< / span > }< / div >
2021-10-26 03:34:27 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "a0ddf1224851353fc92bfbff6f499fa97" name = "a0ddf1224851353fc92bfbff6f499fa97" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a0ddf1224851353fc92bfbff6f499fa97" > ◆ < / a > < / span > main()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > int main < / td >
< td > (< / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > argc< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > char *  < / td >
< td class = "paramname" > < em > argv< / em > []  < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Main function. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramname" > argc< / td > < td > commandline argument count (ignored) < / td > < / tr >
< tr > < td class = "paramname" > argv< / td > < td > commandline array of arguments (ignored) < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > 0 on exit < / dd > < / dl >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 176< / span > {< / div >
< div class = "line" > < span class = "lineno" > 177< / span > < span class = "comment" > /* output alaw encoded by encode() */< / span > < / div >
< div class = "line" > < span class = "lineno" > 178< / span > uint8_t coded[< a class = "code hl_define" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ];< / div >
< div class = "line" > < span class = "lineno" > 179< / span > < / div >
< div class = "line" > < span class = "lineno" > 180< / span > < span class = "comment" > /* output pcm decoded by decode() from coded[LEN] */< / span > < / div >
< div class = "line" > < span class = "lineno" > 181< / span > int16_t decoded[< a class = "code hl_define" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ];< / div >
< div class = "line" > < span class = "lineno" > 182< / span > < / div >
< div class = "line" > < span class = "lineno" > 183< / span > < a class = "code hl_function" href = "../../df/d27/alaw_8c.html#a840bf13d2e4d75d38fb7bf3a655152f5" > test< / a > (pcm, coded, decoded, < a class = "code hl_define" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ); < span class = "comment" > // run self-test implementations< / span > < / div >
< div class = "line" > < span class = "lineno" > 184< / span > < / div >
< div class = "line" > < span class = "lineno" > 185< / span > < span class = "comment" > /* print test pcm inputs */< / span > < / div >
< div class = "line" > < span class = "lineno" > 186< / span > printf(< span class = "stringliteral" > " inputs: " < / span > );< / div >
< div class = "line" > < span class = "lineno" > 187< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < < a class = "code hl_define" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ; i++)< / div >
< div class = "line" > < span class = "lineno" > 188< / span > {< / div >
< div class = "line" > < span class = "lineno" > 189< / span > printf(< span class = "stringliteral" > " %d " < / span > , pcm[i]);< / div >
< div class = "line" > < span class = "lineno" > 190< / span > }< / div >
< div class = "line" > < span class = "lineno" > 191< / span > printf(< span class = "stringliteral" > " \n" < / span > );< / div >
< div class = "line" > < span class = "lineno" > 192< / span > < / div >
< div class = "line" > < span class = "lineno" > 193< / span > < span class = "comment" > /* print encoded alaw */< / span > < / div >
< div class = "line" > < span class = "lineno" > 194< / span > printf(< span class = "stringliteral" > " encode: " < / span > );< / div >
< div class = "line" > < span class = "lineno" > 195< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < < a class = "code hl_define" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ; i++)< / div >
< div class = "line" > < span class = "lineno" > 196< / span > {< / div >
< div class = "line" > < span class = "lineno" > 197< / span > printf(< span class = "stringliteral" > " %u " < / span > , coded[i]);< / div >
< div class = "line" > < span class = "lineno" > 198< / span > }< / div >
< div class = "line" > < span class = "lineno" > 199< / span > printf(< span class = "stringliteral" > " \n" < / span > );< / div >
< div class = "line" > < span class = "lineno" > 200< / span > < / div >
< div class = "line" > < span class = "lineno" > 201< / span > < span class = "comment" > /* print decoded pcm */< / span > < / div >
< div class = "line" > < span class = "lineno" > 202< / span > printf(< span class = "stringliteral" > " decode: " < / span > );< / div >
< div class = "line" > < span class = "lineno" > 203< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < < a class = "code hl_define" href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > ; i++)< / div >
< div class = "line" > < span class = "lineno" > 204< / span > {< / div >
< div class = "line" > < span class = "lineno" > 205< / span > printf(< span class = "stringliteral" > " %d " < / span > , decoded[i]);< / div >
< div class = "line" > < span class = "lineno" > 206< / span > }< / div >
< div class = "line" > < span class = "lineno" > 207< / span > printf(< span class = "stringliteral" > " \n" < / span > );< / div >
< div class = "line" > < span class = "lineno" > 208< / span > < / div >
< div class = "line" > < span class = "lineno" > 209< / span > < span class = "comment" > /* It can be seen that the encoded alaw is smaller than the input PCM, so< / span > < / div >
< div class = "line" > < span class = "lineno" > 210< / span > < span class = "comment" > * the purpose of compression is achieved. And the decoded PCM is almost the< / span > < / div >
< div class = "line" > < span class = "lineno" > 211< / span > < span class = "comment" > * same as the original input PCM, which verifies the correctness of the< / span > < / div >
< div class = "line" > < span class = "lineno" > 212< / span > < span class = "comment" > * decoding. The reason why it is not exactly the same is that there is< / span > < / div >
< div class = "line" > < span class = "lineno" > 213< / span > < span class = "comment" > * precision loss during encode / decode. */< / span > < / div >
< div class = "line" > < span class = "lineno" > 214< / span > < / div >
< div class = "line" > < span class = "lineno" > 215< / span > < span class = "keywordflow" > return< / span > 0;< / div >
< div class = "line" > < span class = "lineno" > 216< / span > }< / div >
2021-10-26 03:34:27 +08:00
< div class = "ttc" id = "aalaw_8c_html_a05b49c662c073f89e86804f7856622a0" > < div class = "ttname" > < a href = "../../df/d27/alaw_8c.html#a05b49c662c073f89e86804f7856622a0" > LEN< / a > < / div > < div class = "ttdeci" > #define LEN< / div > < div class = "ttdoc" > Linear input code | Compressed code | Linear output code ---------------—+--------------—+-----------...< / div > < div class = "ttdef" > < b > Definition:< / b > alaw.c:28< / div > < / div >
< div class = "ttc" id = "aalaw_8c_html_a840bf13d2e4d75d38fb7bf3a655152f5" > < div class = "ttname" > < a href = "../../df/d27/alaw_8c.html#a840bf13d2e4d75d38fb7bf3a655152f5" > test< / a > < / div > < div class = "ttdeci" > static void test(int16_t *pcm, uint8_t *coded, int16_t *decoded, size_t len)< / div > < div class = "ttdoc" > Self-test implementations.< / div > < div class = "ttdef" > < b > Definition:< / b > alaw.c:148< / div > < / div >
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../df/d27/alaw_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.svg" width = "154" height = "38" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
< / div >
< / div >
< a id = "a840bf13d2e4d75d38fb7bf3a655152f5" name = "a840bf13d2e4d75d38fb7bf3a655152f5" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a840bf13d2e4d75d38fb7bf3a655152f5" > ◆ < / a > < / span > test()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "mlabels" >
< tr >
< td class = "mlabels-left" >
< table class = "memname" >
< tr >
< td class = "memname" > static void test < / td >
< td > (< / td >
< td class = "paramtype" > int16_t *  < / td >
< td class = "paramname" > < em > pcm< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > uint8_t *  < / td >
< td class = "paramname" > < em > coded< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int16_t *  < / td >
< td class = "paramname" > < em > decoded< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > size_t  < / td >
< td class = "paramname" > < em > len< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / td >
< td class = "mlabels-right" >
< span class = "mlabels" > < span class = "mlabel" > static< / span > < / span > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
< p > Self-test implementations. < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramname" > pcm< / td > < td > signed 16bit pcm array < / td > < / tr >
< tr > < td class = "paramname" > coded< / td > < td > unsigned 8bit alaw array < / td > < / tr >
< tr > < td class = "paramname" > decoded< / td > < td > signed 16bit pcm array < / td > < / tr >
< tr > < td class = "paramname" > len< / td > < td > length of test array < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > void < / dd > < / dl >
2022-01-15 04:11:27 +08:00
< div class = "fragment" > < div class = "line" > < span class = "lineno" > 149< / span > {< / div >
< div class = "line" > < span class = "lineno" > 150< / span > < span class = "comment" > /* run encode */< / span > < / div >
< div class = "line" > < span class = "lineno" > 151< / span > < a class = "code hl_function" href = "../../df/d27/alaw_8c.html#a751d8e2c1975706e4d876316518c54c4" > encode< / a > (coded, pcm, len);< / div >
< div class = "line" > < span class = "lineno" > 152< / span > < / div >
< div class = "line" > < span class = "lineno" > 153< / span > < span class = "comment" > /* check encode result */< / span > < / div >
< div class = "line" > < span class = "lineno" > 154< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < len; i++)< / div >
< div class = "line" > < span class = "lineno" > 155< / span > {< / div >
< div class = "line" > < span class = "lineno" > 156< / span > assert(coded[i] == r_coded[i]);< / div >
< div class = "line" > < span class = "lineno" > 157< / span > }< / div >
< div class = "line" > < span class = "lineno" > 158< / span > < / div >
< div class = "line" > < span class = "lineno" > 159< / span > < span class = "comment" > /* run decode */< / span > < / div >
< div class = "line" > < span class = "lineno" > 160< / span > < a class = "code hl_function" href = "../../df/d27/alaw_8c.html#a093ac72124e3c2268d1150676e63175d" > decode< / a > (decoded, coded, len);< / div >
< div class = "line" > < span class = "lineno" > 161< / span > < / div >
< div class = "line" > < span class = "lineno" > 162< / span > < span class = "comment" > /* check decode result */< / span > < / div >
< div class = "line" > < span class = "lineno" > 163< / span > < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > size_t< / span > i = 0; i < len; i++)< / div >
< div class = "line" > < span class = "lineno" > 164< / span > {< / div >
< div class = "line" > < span class = "lineno" > 165< / span > assert(decoded[i] == r_decoded[i]);< / div >
< div class = "line" > < span class = "lineno" > 166< / span > }< / div >
< div class = "line" > < span class = "lineno" > 167< / span > }< / div >
2021-10-26 03:34:27 +08:00
< div class = "ttc" id = "aalaw_8c_html_a093ac72124e3c2268d1150676e63175d" > < div class = "ttname" > < a href = "../../df/d27/alaw_8c.html#a093ac72124e3c2268d1150676e63175d" > decode< / a > < / div > < div class = "ttdeci" > void decode(int16_t *out, uint8_t *in, size_t len)< / div > < div class = "ttdoc" > 8bit alaw to 16bit pcm< / div > < div class = "ttdef" > < b > Definition:< / b > alaw.c:107< / div > < / div >
< div class = "ttc" id = "aalaw_8c_html_a751d8e2c1975706e4d876316518c54c4" > < div class = "ttname" > < a href = "../../df/d27/alaw_8c.html#a751d8e2c1975706e4d876316518c54c4" > encode< / a > < / div > < div class = "ttdeci" > void encode(uint8_t *out, int16_t *in, size_t len)< / div > < div class = "ttdoc" > 16bit pcm to 8bit alaw< / div > < div class = "ttdef" > < b > Definition:< / b > alaw.c:46< / div > < / div >
< / div > <!-- fragment -->
< / div >
< / div >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
<!-- start footer part -->
< div id = "nav-path" class = "navpath" > <!-- id is needed for treeview function! -->
< ul >
< li class = "navelem" > < a class = "el" href = "../../dir_a5f32cf82ad289a7dac212f63f40f55b.html" > audio< / a > < / li > < li class = "navelem" > < a class = "el" href = "../../df/d27/alaw_8c.html" > alaw.c< / a > < / li >
2022-06-08 02:13:03 +08:00
< li class = "footer" > Generated by < a href = "https://www.doxygen.org/index.html" > < img class = "footer" src = "../../doxygen.svg" width = "104" height = "31" alt = "doxygen" / > < / a > 1.9.4 < / li >
2021-10-26 03:34:27 +08:00
< / ul >
< / div >
< / body >
< / html >