00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "MMFExPcm8ToPcm16Codec.h"
00018
00019
00020
00021 CMMFCodec* CMMFExPcm8Pcm16Codec::NewL(TAny* )
00022 {
00023 CMMFExPcm8Pcm16Codec* self=new(ELeave) CMMFExPcm8Pcm16Codec();
00024 return self;
00025 }
00026
00027
00028
00029 TCodecProcessResult CMMFExPcm8Pcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
00030 {
00031 TCodecProcessResult result;
00032 result.iStatus = TCodecProcessResult::EProcessIncomplete;
00033
00034
00035 iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
00036 iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
00037
00038 const TUint dstMaxLen = iDst->Data().MaxLength();
00039 if (!dstMaxLen)
00040 User::Leave(KErrArgument);
00041
00042
00043 TUint srcUse = (dstMaxLen - iDst->Position()) / 2;
00044 const TUint srcLen = iSrc->Data().Length();
00045 const TUint sourceRemain = srcLen - iSrc->Position();
00046
00047
00048
00049 srcUse = (srcUse<sourceRemain ? srcUse : sourceRemain);
00050
00051
00052 TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr());
00053 pSrc += iSrc->Position();
00054 TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr());
00055 pDst += iDst->Position();
00056
00057 Convert(pSrc, pDst, srcUse );
00058
00059 if ((srcUse * 2) + iDst->Position() < dstMaxLen)
00060 result.iStatus = TCodecProcessResult::EDstNotFilled;
00061
00062 else if (srcUse + iSrc->Position() >= srcLen)
00063 result.iStatus = TCodecProcessResult::EProcessComplete;
00064
00065 result.iSrcBytesProcessed = srcUse;
00066 result.iDstBytesAdded = srcUse * 2;
00067
00068 iDst->Data().SetLength(iDst->Position() + (srcUse * 2));
00069
00070 return result;
00071 }
00072
00073
00074
00075 void CMMFExPcm8Pcm16Codec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
00076 {
00077 const TInt KAndMask8bit = 0xff;
00078 TInt s16;
00079 while (aSamples--)
00080 {
00081 s16 = (*aSrc++)<<8;
00082 *aDst++ = STATIC_CAST( TInt8, s16&KAndMask8bit);
00083 *aDst++ = STATIC_CAST( TInt8, (s16>>8)&KAndMask8bit);
00084 }
00085 }