Namespaces
Variants
Actions
Revision as of 08:28, 31 July 2012 by hamishwillee (Talk | contribs)

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

Jump to: navigation, search
Article Metadata

Article
Created: mudhalvan (30 May 2007)
Last edited: hamishwillee (31 Jul 2012)

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;
_LIT(KAudioFilePath,”C:\Data\Test.amr”);
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
             if(header.Length())
               {
               // 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]; 
               }                
         }
100 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved