Click here to Skip to main content
Click here to Skip to main content
Go to top

AMR Audio Encoding

, 17 Feb 2012
Rate this:
Please Sign up or sign in to vote.
Raw Audio data is encoded to AMR-NB audio using opencore-amr library.

Introduction

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.

Background

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 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

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 many useful examples.

Official web site http://www.portaudio.com.

Opencore-AMR

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/ or http://opencore-amr.sourceforge.net/

AMR Encoding Data flow Diagram.

Data flow diagram is as follows

amrencode

Software Details

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 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 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.

History

Initial Version : Rev 1.0

License

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

Share

About the Author

potluri_suresh
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 [modified] Pinmemberonmyway13321-May-13 23:36 
SuggestionYour articles PinmentorDaveAuld18-Feb-12 7:53 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 18 Feb 2012
Article Copyright 2012 by potluri_suresh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid