18 October 2005

Do you know how to convert to AMR using CMMFCodec?

This task can be tricky because of lack of the documentation on AMR-NB codec in Symbian. The following code will work on Series 60 2.0 devices:

First of all we declare missing declaration from old AmrCodec.h from Series 60 1.0 SDK:

class TAmrEncParams

{

public:

inline TAmrEncParams();

public:

TInt iMode; // encoding mode 0-7 (0=MR475,1=MR515,...,7=MR122,
default 7)


TInt iDTX; // DTX flag (TRUE or default FALSE)

};

TAmrEncParams::TAmrEncParams() :

iMode(7), iDTX(0) {}

And we will also declare UIDs of AMR codecs:

#define KAdvancedUidCodecPCM16ToAMR 0x101FAF68
#define KAdvancedUidCodecAMRToPCM16 0x101FAF67

This is the function that convers PCM data to AMR-NB (note that CMMFPtrBuffer class you can use only on Series 60 2.0 FP2 SDK, on earlier SDKs you have to use CMMFDescriptorBuffer). Size of aDes parameter is supposed to be equal to 320 bytes.

HBufC8* ConvertFromPCMToAMRNBL( const TPtr8& aDes, TInt aMode )

{

TAmrEncParams taepParams;

taepParams.iMode = aMode;

cmmfcCodec = CMMFCodec::NewL(TUid::Uid(KAdvancedUidCodecPCM16ToAMR ));

CleanupStack::PushL( cmmfcCodec );

cmmfcCodec->ConfigureL( TUid::Uid(KAdvancedUidCodecPCM16ToAMR), ( const TDesC8& ) taepParams );
ptrbPCM16 = CMMFPtrBuffer::NewL();

CleanupStack::PushL( ptrbPCM16 );

ptrbPCM16->SetPtr( aDes );

desbAMRNB = CMMFDescriptorBuffer::NewL( 32 );

CleanupStack::PushL( desbAMRNB );

TCodecProcessResult result = cmmfcCodec->ProcessL( * ptrbPCM16, * desbAMRNB );

if ( ( result.iStatus != TCodecProcessResult::EProcessComplete )

( result.iSrcBytesProcessed != ( TUint ) aDes.Length() ) )

return NULL;

CleanupStack::Pop( 2 ); // cmmfcCodec, ptrbPCM16

HBufC8* pAMRData = desbAMRNB->Data().AllocL();

CleanupStack::Pop( 1 ); // desbAMRNB

return pAMRData;

}

No comments: