Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
G.711
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Types== G.711 defines two main [[companding]] algorithms, the [[μ-law algorithm]] and [[A-law algorithm]]. Both are [[logarithmic scale|logarithmic]], but A-law was specifically designed to be simpler for a computer to process{{Citation Needed|date=October 2023}}. The standard also defines a sequence of repeating code values which defines the power level of 0 [[Decibel|dB]]. The μ-law and A-law algorithms encode 14-bit and 13-bit signed linear PCM samples (respectively) to logarithmic 8-bit samples. Thus, the G.711 [[data compression|encoder]] will create a 64 kbit/s bitstream for a signal sampled at 8 kHz.<ref name=":0" /> G.711 μ-law tends to give more resolution to higher range signals while G.711 A-law provides more quantization levels at lower signal levels. The terms ''PCMU'', ''G711u'' and ''G711MU'' are also used for G.711 μ-law, and ''PCMA'' and ''G711A'' for G.711 A-law.<ref>{{cite web |url=http://www.grandstream.com/support/faq/common-questions/video/voice/speech-codecs |title=Video/Voice/Speech Codecs |website=Grandstream=|access-date= 19 July 2020}}</ref> === A-law === {{Main|A-law algorithm}} A-law encoding thus takes a 13-bit signed linear audio sample as input and converts it to an 8 bit value as follows: {| class="wikitable" style="text-align:left" |- ! Linear input code<br><ref group=note>This value is produced by taking the [[two's complement]] representation of the input value, and inverting all bits after the sign bit if the value is negative.</ref> ! Compressed code<br>XOR 01010101 ! Linear output code<br><ref group=note>[[Signed magnitude]] representation</ref> |- | <code>s0000000abcdx</code> || <code>{{overline|s}}000abcd</code> || <code>s0000000abcd1</code> |- | <code>s0000001abcdx</code> || <code>{{overline|s}}001abcd</code> || <code>s0000001abcd1</code> |- | <code>s000001abcdxx</code> || <code>{{overline|s}}010abcd</code> || <code>s000001abcd10</code> |- | <code>s00001abcdxxx</code> || <code>{{overline|s}}011abcd</code> || <code>s00001abcd100</code> |- | <code>s0001abcdxxxx</code> || <code>{{overline|s}}100abcd</code> || <code>s0001abcd1000</code> |- | <code>s001abcdxxxxx</code> || <code>{{overline|s}}101abcd</code> || <code>s001abcd10000</code> |- | <code>s01abcdxxxxxx</code> || <code>{{overline|s}}110abcd</code> || <code>s01abcd100000</code> |- | <code>s1abcdxxxxxxx</code> || <code>{{overline|s}}111abcd</code> || <code>s1abcd1000000</code> |} <references group=note/> Where {{code|s}} is the sign bit, <code>{{overline|s}}</code> is its inverse (i.e. positive values are encoded with [[most significant bit|MSB]] = {{var|{{overline|s}}}} = 1), and bits marked {{code|x}} are discarded. Note that the first column of the table uses different representation of negative values than the third column. So for example, input decimal value −21 is represented in binary after bit inversion as 1000000010100, which maps to 00001010 (according to the first row of the table). When decoding, this maps back to 1000000010101, which is interpreted as output value −21 in decimal. Input value +52 (0000000110100 in binary) maps to 10011010 (according to the second row), which maps back to 0000000110101 (+53 in decimal). This can be seen as a [[Floating-point arithmetic|floating-point]] number with 4 bits of [[Significand|mantissa]] {{var|m}} (equivalent to a 5-bit precision), 3 bits of [[exponent]] {{var|e}} and 1 sign bit {{var|s}}, formatted as <code>{{overline|s}}eeemmmm</code> with the decoded linear value {{var|y}} given by formula :<math>y = (-1)^s \cdot (16 \cdot \min \{ e, 1 \} + m + 0.5) \cdot 2^{\max \{ e, 1 \} },</math> which is a 13-bit signed integer in the range ±1 to ±(2{{sup|12}} − 2{{sup|6}}). Note that no compressed code decodes to zero due to the addition of 0.5 (half of a quantization step). In addition, the standard specifies that all resulting even bits ([[least significant bit|LSB]] is even) are inverted before the octet is transmitted. This is to provide plenty of 0/1 transitions to facilitate the [[clock recovery]] process in the PCM receivers. Thus, a silent A-law encoded PCM channel has the 8 bit samples coded 0xD5 instead of 0x80 in the octets. When data is sent over E0 ([[G.703]]), MSB (sign) is sent first and LSB is sent last. ITU-T STL<ref>[http://www.itu.int/rec/T-REC-G.191-201003-I/en G.191 : Software tools for speech and audio coding standardization]. Function {{code|alaw_expand}} in file {{code|Software/stl2009/g711/g711.c}}. Itu.int. Retrieved on 2013-09-18.</ref> defines the algorithm for decoding as follows (it puts the decoded values in the 13 most significant bits of the 16-bit output data type). <syntaxhighlight lang="c"> void alaw_expand(lseg, logbuf, linbuf) long lseg; short *linbuf; short *logbuf; { short ix, mant, iexp; long n; for (n = 0; n < lseg; n++) { ix = logbuf[n] ^ (0x0055); /* re-toggle toggled bits */ ix &= (0x007F); /* remove sign bit */ iexp = ix >> 4; /* extract exponent */ mant = ix & (0x000F); /* now get mantissa */ if (iexp > 0) mant = mant + 16; /* add leading '1', if exponent > 0 */ mant = (mant << 4) + (0x0008); /* now mantissa left justified and */ /* 1/2 quantization step added */ if (iexp > 1) /* now left shift according exponent */ mant = mant << (iexp - 1); linbuf[n] = logbuf[n] > 127 /* invert, if negative sample */ ? mant : -mant; } } </syntaxhighlight> See also "ITU-T Software Tool Library 2009 User's manual" that can be found at.<ref>[http://www.itu.int/rec/T-REC-G.191/recommendation.asp?lang=en&parent=T-REC-G.191-200911-I G.191 : ITU-T Software Tool Library 2009 User's manual]. Itu.int (2010-07-23). Retrieved on 2013-09-18.</ref> === μ-law === {{Main|μ-law algorithm}} The μ-law (sometimes referred to as ulaw, G.711Mu, or G.711μ) encoding takes a 14-bit signed linear audio sample in [[two's complement]] representation as input, inverts all bits after the sign bit if the value is negative, adds 33 (binary 100001) and converts it to an 8 bit value as follows: {| class="wikitable" style="text-align:left" |- ! Linear input value<br><ref group=note>This value is produced by taking the [[two's complement]] representation of the input value, inverting all bits after the sign bit if the value is negative, and adding 33.</ref> ! Compressed code<br>XOR 11111111 ! Linear output value<br><ref group=note>[[Signed magnitude]] representation. Final result is produced by decreasing the magnitude of this value by 33.</ref> |- | <code>s00000001abcdx</code> || <code>s000abcd</code> || <code>s00000001abcd1</code> |- | <code>s0000001abcdxx</code> || <code>s001abcd</code> || <code>s0000001abcd10</code> |- | <code>s000001abcdxxx</code> || <code>s010abcd</code> || <code>s000001abcd100</code> |- | <code>s00001abcdxxxx</code> || <code>s011abcd</code> || <code>s00001abcd1000</code> |- | <code>s0001abcdxxxxx</code> || <code>s100abcd</code> || <code>s0001abcd10000</code> |- | <code>s001abcdxxxxxx</code> || <code>s101abcd</code> || <code>s001abcd100000</code> |- | <code>s01abcdxxxxxxx</code> || <code>s110abcd</code> || <code>s01abcd1000000</code> |- | <code>s1abcdxxxxxxxx</code> || <code>s111abcd</code> || <code>s1abcd10000000</code> |} <references group=note/> Where {{code|s}} is the sign bit, and bits marked {{code|x}} are discarded. In addition, the standard specifies that the encoded bits are inverted before the octet is transmitted. Thus, a silent μ-law encoded PCM channel has the 8 bit samples transmitted 0xFF instead of 0x00 in the octets. Adding 33 is necessary so that all values fall into a compression group and it is subtracted back when decoding. Breaking the encoded value formatted as <code>seeemmmm</code> into 4 bits of mantissa {{var|m}}, 3 bits of exponent {{var|e}} and 1 sign bit {{var|s}}, the decoded linear value {{var|y}} is given by formula :<math>y = (-1)^s \cdot [(33 + 2m) \cdot 2^e - 33],</math> which is a 14-bit signed integer in the range ±0 to ±8031. Note that 0 is transmitted as 0xFF, and −1 is transmitted as 0x7F, but when received the result is 0 in both cases.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)