VoIP Codecs

VoIP Codecs – general overview

Codecs are generally understood to be various mathematical models used to digitally encode (and compress) analog audio information.

Many of these models take into account the human brain’s ability to form an impression from incomplete information. We’ve all seen optical illusions; likewise, voice-compression algorithms take advantage
of our tendency to interpret what we believe we  should hear,  rather  than what we actually hear.

“According to research at an English university, it doesn’t matter in what order the letters in a word are,  the
olny iprmoetnt tihng is taht frist and lsat ltteres are in the rghit pclae. The rset can be a toatl mses and you
can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed ervey lteter by istlef, but the wrod as a
wlohe.” (The source of this quote is unknown―see http://www.bisso.com/ujg_archives/000228.html.) We do
the same thing with sound―if there is enough information, our brain can fill in the gaps.

The purpose of the various encoding algorithms is to strike a balance between bandwidth efficiency and voice quality. On an audio CD, quality is far more important than saving bandwidth, so the audio is quantized at 16 bits
(x2 times for stereo as there are left and a right channels), with a sampling rate of 44,100 Hz. Considering that the CD was invented in the late 1970′s, this was quite impressive stuff back then. The telephone network does not require this level of quality (and needs to optimize bandwidth), so telephone signals are encoded using 8 bits, at a sampling frequency of 8,000 Hz.

Originally, the term codec referred to a COder/DECoder: a device that converts between analog and digital. Now, the term seems to relate more to COmpression/DECompression.


Bandwidth requirements for different VoIP codecs you can find on this page.

G.711 (ulaw/alaw)

G.711 is the fundamental codec of the PSTN

. In fact, if someone refers to PCM with respect to a telephone network, you are allowed to think of G.711. Two companding methods are used: μlaw in North America and alaw in the rest of the world. Either one delivers an 8-bit word transmitted 8,000 times per second. If you do the math, you will see that this requires 64,000 bits to be transmitted per second. Many people will tell you that G.711  is an uncompressed codec. This  is not exactly true, as companding is considered a form of compression. What is true is that G.711 is the base codec from which all of the others are derived. G.711 imposes minimal (almost zero) load on the CPU.

G.711 codec has 64 Kbps for Data bitrate (DSP output rage without IP headers) and do not require a license. Actual bandwidth requirements may vary from network type and protocols used. Approximate requirements for average Internet connection TCP/IP with packet overheads is 80 Kbit/s per each active line for each direction. Complete comparison table with different codec and payloads you can find here.

G.726

G.726  codec has been around for some time (it used to be G.721, which is now obsolete), and it is one of the original compressed codecs. It is also known as Adaptive Differential Pulse-Code Modulation (ADPCM), and it can run at several bitrates. The most common rates are 16 Kbps, 24 Kbps, and 32 Kbps. Most popular rate for this codec is ADPCM-32 rate. G.726 offers quality nearly identical to G.711, but it uses only half the bandwidth. This
is possible because rather than sending the result of the quantization measurement, it sends only enough information to describe the difference between the current sample and the previous one. G.726 fell from favor in the 1990′s due to its inability to carry modem and fax signals, but because of its bandwidth and CPU performance ratio it is now
making a comeback. G.726 is especially attractive because it does not require a lot of computational work from the system.

G.726 codec has 16/24/32/40 Kbps for Data bitrate, most popular and commonly used is 32 Kbps. License is not required. For bandwidth requirements please see this page.

G.723.1

G.723.1 official name is Dual rate speech coder for multimedia communications transmitting at 5.3 and 6.3 kbit/s. Note that this is a completely different codec from G.723.

G.723.1 can operate at  6.3 kbit/s (using 24 byte frames) using a MPC-MLQ algorithm or 5.3 kbit/s (using 20 byte frames) using an ACELP algorithm. Use of G.723.1 requires a license for the patents that cover the algorithm. The last patent will expire in 2014. The authorized intellectual property rights (IPR) Licensing Administrator for G.723.1 technology is Sipro Lab Telecom.Members of the G.723.1 patent pool are AudioCodes, France Telecom, Université de Sherbrooke, Nippon Telegraph and Telephone Corporation and Nokia.

G.723 bandwidth requirements can be found here.

G.729A

Considering how little bandwidth it uses, G.729A delivers impressive sound quality. It does this through the use of Conjugate-Structure Algebraic-Code-Excited Linear Prediction (CS-ACELP). Because of patents, you can’t use G729A without paying a licensing fee; however, it is extremely popular and well supported on many different phones and systems. To achieve its impressive compression ratio, this codec requires an equally impressive amount of effort from the CPU. For example on Asterisk system, the use of heavily compressed codecs will quickly bog down the CPU.

CELP is a popular method of compressing speech. By mathematically modeling the various ways humans make sounds, a “code book” of sounds can be built. Rather than sending an actual sampled sound, a code corresponding to the sound is determined. CELP codecs take this information (which by itself would produce a very robot-like sound) and attempt to add the personality back in. (Of course, there is much more to it than that.) Jason Woodward’s Speech Coding page is a source of helpful information for the non-mathematically inclined. This is fairly heavy stuff, though, so wear your thinking cap.

G.729A uses 8 Kbps of bandwidth (pure DSP rate). Requires a license. Bandwidth consumption by 1 active VoIP line using SIP: 24 Kbit/s.

GSM

GSM is the “darling” codec of almost all Asterisk/trixbox setups. This codec does not come encumbered with a licensing requirement the way that G.729A does, and it offers outstanding performance with respect to the demand it places on the CPU. The sound quality is generally considered to be of a lesser grade than that produced by G.729A, but much of this comes down to personal opinion. You must try it out.

iLBC

The Internet Low Bitrate Codec (iLBC) provides an attractive mix of low bandwidth usage and quality, and it is especially well suited to sustaining reasonable quality on lossy network links. Naturally, Asterisk supports it (and support elsewhere is growing), but it is not as popular as the ITU codecs and, thus, may not be compatible with common IP telephones and commercial VoIP systems. IETF RFCs 3951 and 3952 have been published in support of iLBC, and iLBC is on the IETF standards track. Because iLBC uses complex algorithms to achieve its high levels of compression, it has a fairly high CPU cost in Asterisk.
While you are allowed to use iLBC without paying royalty fees, the holder of the iLBC patent, Global IP Sound (GIPS), wants to know whenever you use it in a commercial application. The way you do that is by downloading and printing a copy of the iLBC license, signing it, and returning it to GIPS.

iLBC operates at 13.3 Kbps (30 ms frames) and 15.2 Kbps (20 ms frames).

Speex

Speex is a variable bitrate (VBR) codec, which means that it is able to dynamically modify its bitrate to respond to changing network conditions. It is offered in both narrowband and wideband versions, depending on whether you want telephone quality or better. Speex is a totally free codec, licensed under the Xiph.org variant of the BSD license.

Speex can operate at anywhere from 2.15 to 22.4 Kbps, due to its variable bitrate.

Please see also typical payload and  bandwidth requirements for most popular codecs in VoIP industry

 

If you are looking for G.729 and/or G.723 for your Asterisk I’d recommend to check this site – you will find there as binaries to build from source as well as ready codec_g729/723*.so files  (already compiled on different platforms).

Some notes:

Troubleshooting

  • Noise or metalic sound with codec_g723
    Configure /etc/asterisk/codecs.conf [g723] sendrate=63 or 53 as described at the top of this page.
  • Distorted sound
    Disable VAD and CNG in phone and/or your VOIP provider.
  • show translation – codec is not loaded
    Bump asterisk verbosity level with -vv and watch for messages right after ‘loading module codec_g729…’
  • Module codec_g72… does not provide a description
    Choose proper version of the codec to match your Asterisk version. TRUNK is for SVN TRUNK – the next yet unrealeased major version of Asterisk.
  • Module codec_g72… was not compiled with the same compile-time options as this version of Asterisk.
    Try new 1.4 and/or TRUNK builds.
  • loader.c… /usr/lib/asterisk/modules/codec_g72…: cannot restore segment prot after reloc: Permission denied
    Execute:
    $ chcon -t textrel_shlib_t /usr/lib/asterisk/modules/codec_g72[39]*.so
    This happens when SELinux is enabled and Asterisk process cannot load the codec because of ELF TEXTREL in shared library. This is how IPP works and that is fine.
  • loader.c… /usr/lib/asterisk/modules/codec_g72…: cannot enable executable stack as shared object requires: Permission denied
    Execute:
    $ execstack -c /usr/lib/asterisk/modules/codec_g72[39]*.so
  • Error loading module codec_g72…: cannot open shared object file: No such file or directory
    Check
    $ ldd codec_g729.so
    $ strace -o trace.log -efile -f asterisk
    send ldd output and trace.log file to Asterisk G.729 Google group.
  • Error loading module codec_g72…: wrong ELF class: ELFCLASS32
    Use x86_64 binaries because you’re running 64-bit OS.
  • $ ldd codec_g729.so: not a dynamic executable
    You are running 32-bit, see Notes - note #2
  • Asterisk crashing at startup
    If Pentium4 codec is not working, try -no-sse builds, try Pentium3. Try ICC builds. Doesn’t work – try Pentium and Debug builds.
  • Asterisk still crashing at startup
    Compile asterisk with CFLAGS=-g
    Run asterisk in gdb (with original and -debug version of the codec):
    $ gdb /usr/sbin/asterisk
    (gdb) r -cvvv
    when it crashes do:
    (gdb) set disassembly-flavor intel
    (32-bit gdb 6.x) disassemble $eip $eip+20
    (32-bit gdb 7.x) disassemble $eip, $eip+20
    (64-bit gdb 6.x) disassemble $rip $rip+20
    (64-bit gdb 7.x) disassemble $rip, $rip+20
    (gdb) info registers
    (gdb) info threads
    (gdb) bt
    (gdb) l
    (gdb) q
    Send an output to Asterisk G.729 Google group together with the result of ‘cat /proc/cpuinfo’.
  • Why these Illegal instruction errors?
    For in-depth technical information read http://gcc.gnu.org/PR32893 and http://bugs.gentoo.org/show_bug.cgi?id=151394.
Google Groups
Asterisk G.729

 

 

Leave a Reply