High Definition VoIP on Asterisk-FreePBX

A short guide on how to use High Definition VoIP on Asterisk and FreePBX.

What is it
HD VoIP in the Asterisk world involves selecting the g722 codec for VoIP calls.  g722 is known as a wideband codec as opposed to g711 which is narrowband.  The nice thing about it is that it does not require any more bandwidth than g711.  Both require 64kbit/s each way for a 2-way conversation.

The difference is that g722 employs compression combined with a higher sample rate to obtain a practical acoustic bandwidth of 50 Hz-7000 Hz as opposed to g711 which has a practical acoustic bandwidth of 200-3000 Hz.  The difference in voice quality is quite noticeable.  Instead of sounding like you are talking into a tin can it now sounds like the other person is in the same room.  You can hear more subtle nuances in the person’s voice and certain letters/syllables that are hard to distinguish on regular calls become much easier. 

If one endpoint is using g722 and the other is using g711, the endpoint using g722 will hear better sound quality from the other end but the g711 end will not notice much if any difference. Transcoding overhead between g722 and g711 is minimal.  Roughly equivalent to half the transcoding overhead between g711 and GSM.

How to enable it
You need to be using Asterisk 1.6 or a patched version of Asterisk 1.4.  You need at least one endpoint that supports g722 such as an Aastra 67xxi phone.  Enable g722 on the endpoint as the first choice, falling back to g711 or some other codec if Asterisk-FreePBX does not try to negotiate g722 first.

On asterisk you simply have to edit /etc/asterisk/sip.conf and place "allow=g722" before all the other "allow=" statements and reload asterisk.  This will make asterisk try negotiate g722 before the other codec’s.

On FreePBX it is a little more complicated.  FreePBX does not have a feature for re-arranging the priority of codec’s.  At least not yet although I have submitted a feature request.  If you try editing the sip.conf file FreePBX will simply re-write the file when you reload.  You can add the "allow=g722" statement to /etc/asterisk/sip_general_custom.conf and reload FreePBX.  You can also add it via a handy FreePBX module called "Asterisk SIP Settings".  That will add g722 capability to sip.conf but not before the other codec's so it still will not have priority.

There are at least 2 work arounds.  One would be to set the endpoint to ONLY negotiate g722.  Another way is to disallow the other codec's in the SIP settings for the endpoint extension in FreePBX.  This second way is what I did.  Just look for the 'disallow' setting in extensions section of FreePBX.  Enter "g711 & gsm" in that setting for the extension you want to use g722.