Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to find out the mode of an AMR file to set the frame length properly

From Wiki
Jump to: navigation, search
Article Metadata
Created: mudhalvan (30 May 2007)
Last edited: hamishwillee (30 May 2013)

How to find out the mode of an AMR file to set the frame length correctly

The frame length of an AMR file varies according to the mode( bitrate ) of that particular AMR content. Especially while using streaming classes like CMdaAudioOutputStream, the buffers should be loaded according to the frame length which can be resolved from the mode, to which that particular AMR file belongs to.

The mode information of an AMR file can be extracted from the first byte of the first frame( ie, the first byte after the 6 byte AMR header ). Following is the code snippet which demonstrates how to extract the mode information from an AMR file:

const TInt KAMRFrameLenTable[8] = { 13, 14, 16, 18, 20, 21, 27, 32 };
#define KAMRHeaderLength 6
RFs iFs;
RFile iFile;
User:: LeaveIfError(iFs.Connect());
TInt ret = iFile.Open(iFs, KAudioFilePath, EFileRead | EFileStream);
   if(ret != KErrNone)
       { return ret; }
   // reading AMR header
TBuf8<KAMRHeaderLength> header;
 ret = iFile.Read(header, KAMRHeaderLength);
   if(ret == KErrNone)
        iFile.Read(header, 1); // reading 1st byte of the first frame
               // resolving the AMR mode from the first frame’s 1st byte
               TInt mode = (header[0] & 0x38) >> 3; // 0x38 == 00111000
              // frame length is set according to the mode returned
               iFrameLen = KAMRFrameLenTable[mode]; 
This page was last modified on 30 May 2013, at 04:34.
9 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.