To add a codec for SIP/SDP (m=, rtmap, and ftmp), you create a format module in Asterisk: codec_amr.patch
(for m= and rtmap) and res/res_format_attr_amr.c
(for fmtp). However, this requires both call legs to support AMR (pass-through only). If one leg does not support AMR, the call has no audio. Or, if you use the pre-recorded voice and music files of Asterisk, these files cannot be heard, because they are not in AMR but in slin. Therefore, this repository adds not just a format module for the audio-codecs AMR and AMR-WB but a transcoding module as well: codecs/codec_amr.c
.
This is an implementation of IETF RFC 4867. Sometimes, AMR is called AMR Narrowband (AMR-NB). AMR Wideband (ITU-T Recommendation G.722.2) is sometimes abbreviated W-AMR (GSA). GSMA Mobile HD Voice is AMR-WB. Research papers comparing AMR and AMR-WB with other audio codecs: InterSpeech 2010, ICASSP 2010, InterSpeech 2011. Further examples…
This patch is for Asterisk 13. If you use an older version of Asterisk, and AMR without AMR-WB is sufficient in your case, please, have a look at those patches:
The patch was built on top of Asterisk 13.10. If you use a newer version and the patch fails, please, report!
cd /usr/src/
wget downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
tar zxf ./asterisk*
cd ./asterisk*
sudo apt-get --assume-yes install build-essential autoconf libssl-dev libncurses-dev libnewt-dev libxml2-dev libsqlite3-dev uuid-dev libjansson-dev libblocksruntime-dev
Install libraries:
If you do not want transcoding but pass-through only (because of license issues) please, skip this step. To support transcoding, you’ll need to install OpenCORE AMR, for example in Debian/Ubuntu:
sudo apt-get --assume-yes install libopencore-amrnb-dev libopencore-amrwb-dev libvo-amrwbenc-dev
Apply all patches:
wget github.com/traud/asterisk-amr/archive/master.zip
unzip -qq master.zip
rm master.zip
cp --verbose --recursive ./asterisk-amr*/* ./
patch -p0 <./codec_amr.patch
patch -p0 <./build_tools.patch
Run the bootstrap script to re-generate configure:
./bootstrap.sh
Configure your patched Asterisk:
./configure
Enable slin16 in menuselect for transcoding, for example via:
make menuselect.makeopts
./menuselect/menuselect --enable-category MENUSELECT_CORE_SOUNDS
Compile and install:
make
sudo make install
You can test AMR-WB out of the box using
A. (Google Android) CSipSimple
B. (Google Android) CounterPath Bria
C. (Apple iOS) CounterPath Bria
D. (Windows Phone 8) Linphone
On ingress, this module supports the octet-aligned mode and the bandwidth-efficient mode. Currently on egress, only the bandwidth-efficient mode is advertised when transcoding. However, if the originating party supports AMR, it’s mode is passed transparently. Because Linphone supports only the octet-aligned mode, but does not honor the line fmtp
in SDP, the mode is not negotiated correctly and ingress calls create distorted audio in Linphone. This bug is reported to the Linphone team. However, these VoIP/SIP clients offer G.722 and Opus, which should be used for wide-band audio instead. G.722 transcoding is build into Asterisk already. Opus can be added as transcoding module…
Actually, this repository was created for Nokia Mobile Phones which support AMR (since the year 2006) and AMR-WB (since the year 2009) in VoIP/SIP, like:
- Nokia Asha 503 (Asha Software Platform),
- Nokia 303 (Nokia Series 40),
- Nokia E75 (Symbian/S60), and Nokia Belle.
This transcoding module is shoddy work. Therefore, please, double-check the source of codecs/codec_amr.c
for any feature you need. For example IETF RFC 4867 offers frame CRC, robust sorting and interleaving. If you need this, please, add that code or report the device/app which requires this. I simply do not have a testing device for this. Several AMR frames per payload (compound payload) are another issue, for example when FEC or a packetization time (ptime
) longer than 20 ms are used. The transcoding module works for me and contains everything I need. If you cannot code yourself, however, a feature is missing for you, please, report and send me at least a testing device.
- teams of the Android Open Source Project (AOSP), OpenCORE AMR, Debian Multimedia, and Ubuntu for providing the libraries.
- Asterisk team: Thanks to their efforts and architecture this AMR module was written in one working day.
- Sean Bright provided the starting point with his Opus patch.
- Юрий Остапчук provided an code example for the bandwidth-efficient mode.