Click here to Skip to main content
15,944,837 members
Articles / Multimedia / Audio Video

AMR Audio Encoding

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
17 Feb 2012CPOL3 min read 68K   4.1K   17   3
Raw Audio data is encoded to AMR-NB audio using opencore-amr library


This article is the third article of audio capturing, encoding and streaming. It describes how to encode capture PCM data to AMR encoding and write to audio file.


It is for software developers who are interested in audio related applications. Mostly suits for Audio software developers who are interested in encoding and decoding audio files to AMR Narrow Band encoding. It is not required to know AMR encoding and decoding details unless one wants to decode captured data manually.

Total application is written in "C" language and consists of simple functions and simple port audio library and opencore-amr library calls. Anyone who has been working in for quite a time can understand the program.


Port-Audio is a free, cross-platform, open-source, audio I/O library. It lets you write simple audio programs in 'C' or C++ that will compile and run on many platforms including Windows, Macintosh OS X, and Unix (OSS/ALSA). It is intended to promote the exchange of audio software between developers on different platforms. Port Audio software has many useful examples.

Official web site is


Library of OpenCORE Framework implementation of Adaptive Multi Rate Narrowband and Wideband (AMR-NB and AMR-WB) speech codec. Library of VisualOn implementation of Adaptive Multi Rate Wideband (AMR-WB) encoder and Advanced Audio Coding (AAC) encoder.

Official opencore amr web site is or

AMR Encoding Data flow Diagram

Data flow diagram is as follows:


Software Details

For more details on port audio calls, see the port-audio documentation, and AMR narrow band, see opencore-amr documentation.

Step 1: Initialize Port Audio and Register Record Callback Function

Initialize the port audio and open port audio stream with record call back function with the following configurations 8000 sampling rate, 16 bit signed PCM data, frame size of 80 samples mean 10 milliseconds audio data in one frame. After stream is started, record call back is called for every 10 ms with one frame of audio data.

Step 2: Initialize AMR-NB Library

Initialize opencore-amr library with proper configuration parameters to match port-audio capture configuration. opencore-amr encoding interface is initialized by calling its Encoder_Interface_init.

Step 3: Encode Raw Audio Frame

When port-audio record callback is called, raw audio data is stored input buffer, pass the buffer and length to amr encoder, amr encoder returns encoded data.

By calling Encoder_Interface_Encode function, raw audio data is converted to amr-nb encoded data.

Step 4: Write to File

Amr-nb audio has signature header to identify the binary file as amr audio file. Without this AMR signature, amr audio players cannot play the audio file.

Open file pointer and first write AMR signature "#!AMR\n" to binary file and continuously write AMR encoded data. Close the file pointer after completing encoding all audio frames.

Step 6: Close opencore-amr Library

Close all resources related to amr library. opencore exit function is as follows Encoder_Interface_exit.

Step 7: Stop, Close Audio Stream and Close Port Audio

Close stream using Pa_CloseStream() function.

Required Software

The following software are required to execute and listen to captured audio file:

  • VC++, portaudio library/dll
  • opencore amr library/dll and
  • ant amr-nb capable audio player (VLC)

Points of Interest

  • Simple AMR encoding sample


  • Initial version: Rev 1.0


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior) 3k Techonologies
United States United States
Suresh Potluri has worked in Windows device drivers, Solid experience in NDIS Layer, developed many NDIS Miniport drivers. Extensive experience in developing NDIS miniport drivers, building WHQL/DTM setup, clearing all WHQL/DTM tests, and subsequently getting device signature/logo process for the developed drivers. He also was also solely responsible for debugging traps and blue screens for a number of years.
he also worked on many PCI based boards, developed Board support packages, Vx-Works firmware for Power PC, firmware for ARM based boards for Wireless LAN devices.

he is interested in Embedded, NDIS, MPEG.

Previously worked in Tandberg TV, Sunnyvale, Chlesio Communications, Sunnyvale, Hellosoft, Hyderabad.

Comments and Discussions

QuestionGood tutorial Pin
onmyway13321-May-13 23:36
onmyway13321-May-13 23:36 
AnswerRe: Good tutorial Pin
micron_rt29-Jul-16 9:23
micron_rt29-Jul-16 9:23 
SuggestionYour articles Pin
DaveAuld18-Feb-12 7:53
professionalDaveAuld18-Feb-12 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.