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. Thanks for all your past and future contributions.

Archived:Getting sample and bit rate information for audio files using Symbian C++

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Tested with
Devices(s): All (S60)
Platform(s): S60 3rd Edition
S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 3rd Edition (initial release)
Keywords: RMMFController, RMMFAudioControllerCustomCommands
Created: User:Technical writer 2 (February 8, 2007, updated October 21, 2008)
Last edited: hamishwillee (14 Jun 2012)


Sample and bit rate information can be retrieved for some audio formats with the DestinationSampleRateL() and DestinationBitRateL() methods from CMdaAudioRecorderUtility. However, files encoded with codecs like MP3, AAC, or WMA require a different approach.


The below sample code shows how to retrieve sample and bit rate values for any supported audio file. Compiling the code requires APIs from the MMF Controller Framework. These are included in the S60 3rd Edition, Feature Pack 2 SDK. They are also available for S60 3rd Edition, Maintenance Release SDK as the MMF Extensions plug-in.

Include files:

 #include <mdaaudiosampleeditor.h>
#include <mmf\common\mmfcontroller.h>



The following definitions are needed:

  class TFileParams
TFileName iPath;
TInt iReserved;
typedef TPckgBuf<TFileParams> TFileConfig;
* CMyAudioEngine class.
* Uses CMdaAudioRecorderUtility, RMMFController and
* MMF custom commands to retrieve additional information
* about audio files.
* (Some of the implementation omitted for simplicity).

class CMyAudioEngine : public CBase,
public MMdaObjectStateChangeObserver
void GetAudioParamsL( const TDesC& aFileName );
* from MMdaObjectStateChangeObserver

virtual void MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState,
TInt aCurrentState, TInt aErrorCode);
private: // Data
TFileConfig iSourceCfg;
TUint iSampleRate, iBitRate;
TMMFPrioritySettings iMMFPriority;
RMMFController iController;
CMdaAudioRecorderUtility* iUtility;

Implementation of GetAudioParamsL and MoscoStateChangeEvent:

 void CMyAudioEngine::GetAudioParamsL( const TDesC& aFileName )
iSourceCfg().iPath = aFileName;
iMMFPriority.iPriority = EMdaPriorityNormal;
iMMFPriority.iPref = EMdaPriorityPreferenceTimeAndQuality;
if( !iUtility )
iUtility = CMdaAudioRecorderUtility::NewL( *this );
// Remember to delete iUtility in destructor
iUtility->Close(); // Close previous audio clip
iUtility->OpenFileL( iSourceCfg().iPath );
void CMyAudioEngine::MoscoStateChangeEvent( CBase* /*aObject*/,
TInt /*aPreviousState*/,
TInt aCurrentState,
TInt aErrorCode )
if( aErrorCode == KErrNone &&
aCurrentState == CMdaAudioClipUtility::EOpen )
const CMMFControllerImplementationInformation* ctlInfo = 0;
TRAPD(err, ctlInfo = &(iUtility->
if(err != KErrNone)
err = iController.Open( ctlInfo->Uid(), iMMFPriority );
if( err == KErrNone )
TMMFMessageDestination dataSource;
err = iController.AddDataSource( KUidMmfFileSource,
dataSource );
if( err == KErrNone )
RMMFAudioControllerCustomCommands customCommands( iController );
customCommands.GetSourceSampleRate( iSampleRate );
customCommands.GetSourceBitRate( iBitRate );
// See documentation on RMMFAudioControllerCustomCommands
// for other available methods.
// TODO: Handling of other events / errors
This page was last modified on 14 June 2012, at 07:22.
22 page views in the last 30 days.