Scenario:
– you want to know what codecs are used when you make a phone call via your Asterisk PBX
Resolution:
– SSH to your Asterisk Box
– enter Asterisk with verbosity of 9: asterisk -vvvvrrrrr and Asterisk will reply like:
Connected to Asterisk 1.6.0.26-FONCORE-r78 currently running on pbnet (pid = 2697)
Verbosity is at least 4
– make the call and Asterisk will display something like:
— Executing [s@macro-dial:7] Dial(“Local/781@from-internal-22cf;2”, “SIP/781,””,tr”) in new stack
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
== Using SIP VRTP TOS bits 136
== Using SIP VRTP CoS mark 6
— Called 781
— Local/781@from-internal-22cf;1 is ringing
— SIP/781-00000060 is ringing
— Local/781@from-internal-22cf;1 is ringing
– issue the command: sip show channels and Asterisk will display:
pbnet*CLI> sip show channels
Peer User/ANR Call ID Format Hold Last Message
172.24.96.190 781 2aa11d3b0f364f8 0x4 (ulaw) No Init: INVITE
172.47.56.190 (None) 1456BD4049CF121 0x0 (nothing) No Rx: REGISTER
172.17.77.178 777 df35c46b-a9267e 0x4 (ulaw) No Rx: ACK
3 active SIP dialogs
ulaw stands for G711 ulaw
μ-law encoding takes a 14-bit signed linear audio sample as input, increases the magnitude by 32 (binary 10000), and converts it to an 8 bit value as follows:
Linear input code | Compressed code |
s00000001wxyza | s000wxyz |
s0000001wxyzab | s001wxyz |
s000001wxyzabc | s010wxyz |
s00001wxyzabcd | s011wxyz |
s0001wxyzabcde | s100wxyz |
s001wxyzabcdef | s101wxyz |
s01wxyzabcdefg | s110wxyz |
s1wxyzabcdefgh | s111wxyz |
Where s is the sign bit.
In addition, the standard specifies that all result bits are inverted before the octet is transmitted. Thus, a silent μ-law encoded PCM channel has the 8 bit samples coded 0xFF instead of 0x00 in the octets.
Also the “trick” of adding 32 means μ-law does not encode all 14-bit values; inputs must be within ±8159.