This article is 3rd
article of audio capturing, encoding and streaming. It describes to 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
Total application is written in
"C" language 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,
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 many useful
Official web site http://www.portaudio.com.
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 http://sourceforge.net/projects/opencore-amr/
AMR Encoding Data flow Diagram.
Data flow diagram is as follows
For more details on port audio calls see the port-audio
documentation, and AMR narrow band see opencore-amr documentation.
Step1: Initialize port audio and register record callback function.
Initialize the port audio and
open port audio stream with record call back function with 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
to with proper configuration parameters to match port-audio capture
configuration. opencore-amr encoding interface is initialized by calling is 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 amr library. opencore exit function is as follows
Step 7: Stop, close audio stream and close port audio.
Close stream using
The following software are required to execute and listen
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
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.