First public contribution.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "MMFAudioCodecBase.h"
23 // Test system includes
24 #include "TSU_MMF_SWCODECDEVICES.h"
25 #include "TSU_MMF_SwCodecDevices_BufferSizes.h"
26 #include "TSU_MMF_DeviceSuite.h"
27 #include "MMFAudioSPcm16ToALawCodec.h"
28 #include "MMFAudioALawToS16PcmCodec.h"
29 #include "MMFAudioMuLawToS16PcmCodec.h"
30 #include "MMFAudioSPcm16ToMuLawCodec.h"
31 #include "mmfpcm16ToImaAdpcm.h"
32 #include "MmfImaAdpcmtopcm16hwdevice.h"
37 * CTestStep_MMF_SwCodecDevices
40 CTestStep_MMF_SwCodecDevices::CTestStep_MMF_SwCodecDevices()
47 * ~CTestStep_MMF_SwCodecDevices
50 CTestStep_MMF_SwCodecDevices::~CTestStep_MMF_SwCodecDevices()
57 * @param aPtr ref to the test suite
60 void CTestStep_MMF_SwCodecDevices::SetSuite( CTestSuite_MMF_SwCodecDevices* aPtr )
67 * @return CTestSuite_MMF_SwCodecDevices*
70 CTestSuite_MMF_SwCodecDevices* CTestStep_MMF_SwCodecDevices::GetSuite()
79 CTest_MMF_Gsm610::CTest_MMF_Gsm610()
86 * CTest_MMF_SwCodecDevices_U_0001
89 CTest_MMF_SwCodecDevices_U_0001::CTest_MMF_SwCodecDevices_U_0001()
91 // store the name of this test case
92 // this is the name that is used by the script file
93 iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0001-HP");
98 * CTest_MMF_SwCodecDevices_U_0001
101 CTest_MMF_SwCodecDevices_U_0001::~CTest_MMF_SwCodecDevices_U_0001()
111 CTest_MMF_Gsm610::~CTest_MMF_Gsm610()
122 TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepL()
125 TVerdict result = EPass ;
127 CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
128 CleanupStack::PushL(pDecoder);
130 // do the same for the inverse operation
131 CMmfPcm16ToGsm610HwDevice* pEncoder = CMmfPcm16ToGsm610HwDevice::NewL();
132 CleanupStack::PushL(pEncoder);
133 CMMFSwCodec& theEncode = pEncoder->Codec();
135 //[ create buffers of the appropriate size ]
136 const TInt srcBufferSize = theEncode.SourceBufferSize();
137 const TInt sinkBufferSize = theEncode.SinkBufferSize();
138 const TInt codedBufferSize = 76*4* KNumFramesInABuffer; // number of coded buffers * size of coded buffer 63*2
139 iNumCodedFrames = KNumFramesInABuffer; //XXX claculate these constants soon <GK>
141 iScratchData = CMMFDescriptorBuffer::NewL( codedBufferSize);
143 //[ pcm data buffers ]
144 iRefSrcData = CMMFDescriptorBuffer::NewL( srcBufferSize );
145 iDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
147 //[ coded data buffers ]
148 iRefCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
149 iRefDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
150 iCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
152 //[ for now process only the first few buffers
153 // and encode the data]
154 INFO_PRINTF1(_L("Encoding Frame..."));
155 TInt srcFileSize = 0;
156 iSrcFile.Size( srcFileSize);
157 TInt buffLen =iRefSrcData->Data().MaxLength();
158 TInt numBuffers = srcFileSize/buffLen;
159 if( numBuffers > 4 ) // [ not all buffers are processed without error
160 // and this is the intention probably of the test sequences]
162 TInt badBufferCount = 0;
163 TInt goodBufferCount = 0;
165 for( TInt bufferCount = 0; bufferCount < numBuffers; bufferCount++ )
167 //[precondition pointers are ok]
168 ReadDataBufferL(iSrcFile, *iRefSrcData );
170 ParseCodedDataL(iRefCodedData);
172 CMMFSwCodec::TCodecProcessResult encodeRes = theEncode.ProcessL( *iRefSrcData, *iCodedData );
173 if( encodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
175 INFO_PRINTF1( _L("Error Failed to complete coding") );
179 //[ compare results ]
180 if( !CompareEncodeResults( iCodedData, iRefCodedData ) )
192 //[ log number of good buffers & number of bad buffers ]
193 INFO_PRINTF4(_L("Good Buffers %d, Bad Buffers %d, Total Buffers %d"),
194 goodBufferCount, badBufferCount, badBufferCount+goodBufferCount );
196 //[pop data from the cleanup stack ]
197 CleanupStack::PopAndDestroy(2, pDecoder); //pDecoder, theCodec
199 delete iRefSrcData; // reference source data
201 delete iRefCodedData; //reference coded data
202 iRefCodedData = NULL;
203 delete iRefDecodedData; // reference decoded data
204 iRefDecodedData = NULL;
205 delete iCodedData; // buffer of coded data
207 delete iDecodedData; // buffer of actual decoded data
209 delete iScratchData; // scratch data buffer
222 void CTest_MMF_Gsm610::ParseCodedDataL( CMMFDataBuffer* aBuffer )
227 //[ read all the coded data into the scratch buffer from reference file ]
228 ReadDataBufferL( iCodedFile, *iScratchData );
229 TUint8* dest = const_cast<TUint8*>(aBuffer->Data().Ptr());
230 TUint8* src = const_cast<TUint8*>(iScratchData->Data().Ptr());
232 //[ for all the coded frames parse these frames to proper coded form ]
233 for( TInt count = 0; count < iNumCodedFrames; count++ )
235 // parse data to frame
236 ParseFrameL( frame0, src );
237 ParseFrameL( frame1, src );
238 //[ finally pack the two frames into the coded data buffer ]
239 PackFrame0( &frame0, reinterpret_cast<TInt8*>(dest) );
240 PackFrame1( &frame1, reinterpret_cast<TInt8*>(dest) );
241 dest+= KGsmFrameSize;
244 aBuffer->Data().SetLength(KGsmFrameSize*iNumCodedFrames);
249 * @param aFrame this stores the gsm frame in an unpacked structure
250 * @param aBuffer this contains the reference file data as 76 words
253 void CTest_MMF_Gsm610::ParseFrameL( struct codes& aFrame, TUint8* &aSrc )
255 for(TInt i = 0; i < 8; i++ )
257 aFrame.LARc[i] = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
258 aFrame.LARc[i] |= static_cast<TInt16>(*aSrc++ << 8 );
261 for( TInt j = 0; j < 4; j++ )
263 aFrame.sfc[j].Nc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
264 aFrame.sfc[j].Nc |= static_cast<TInt16>(*aSrc++ << 8 );
265 aFrame.sfc[j].bc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
266 aFrame.sfc[j].bc |= static_cast<TInt16>(*aSrc++ << 8 );
267 aFrame.sfc[j].Mc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
268 aFrame.sfc[j].Mc |= static_cast<TInt16>(*aSrc++ << 8 );
269 aFrame.sfc[j].xmaxc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
270 aFrame.sfc[j].xmaxc |= static_cast<TInt16>(*aSrc++ << 8 );
272 for( TInt k = 0; k < 13; k++ )
274 aFrame.sfc[j].xMc[k] = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
275 aFrame.sfc[j].xMc[k] |= static_cast<TInt16>(*aSrc++ << 8 );
284 * DoTestStepPreambleL
287 enum TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepPreambleL(void)
289 TVerdict result = EPass;
290 //[ connect to the file server ]
291 User::LeaveIfError( iFs.Connect());
293 //[ read the ref source data ]
294 if(!GetStringFromConfig(_L("SectionOne"), _L("SourceData01"), iSourceDataFile) ||
295 !GetStringFromConfig(_L("SectionOne"), _L("CodedData01"), iCodedDataFile) ||
296 !GetStringFromConfig(_L("SectionOne"), _L("DecodedData01"), iDecodedDataFile) )
298 return EInconclusive;
301 //[ open the data files]
302 OpenFileL(iSrcFile,iSourceDataFile );
303 OpenFileL(iCodedFile,iCodedDataFile );
304 OpenFileL(iDecodeFile,iDecodedDataFile);
310 * CompareCodedResults
311 * @param aEncodedFrame
316 TBool CTest_MMF_Gsm610::CompareEncodeResults( CMMFDataBuffer* aEncoded, CMMFDataBuffer* aRefFrame )
318 TBool result = ETrue;
320 //[precondition no encoded frames == refframes ]
321 __ASSERT_DEBUG(aEncoded,Panic(EBadArgument));
322 __ASSERT_DEBUG(aRefFrame,Panic(EBadArgument));
324 TInt upperLimit = aEncoded->Data().Length()/KGsmFrameSize;
326 const CMMFDataBuffer* encoded = STATIC_CAST(const CMMFDataBuffer*, aEncoded);
327 const CMMFDataBuffer* reference = STATIC_CAST(CMMFDataBuffer*, aRefFrame);
329 TUint8* pFrames = CONST_CAST(TUint8*,encoded->Data().Ptr());
330 TUint8* pRefFrames = CONST_CAST(TUint8*,reference->Data().Ptr());
332 TInt badFrameCount = 0;
333 TInt goodFrameCount = 0;
336 for( TInt index = 0; index < upperLimit; index++ )
338 //[ compare src and ref frame]
339 if( !CompareGsm610Frames( pFrames, pRefFrames ))
343 INFO_PRINTF2(_L("Bad Frame Number: %d"), index );
349 //[ increment frame pointers by size of gsmencoded frame
350 pFrames += KGsmFrameSize;
351 pRefFrames += KGsmFrameSize;
354 //[ log number of good frames & number of bad frames ]
355 INFO_PRINTF4(_L("Good Frames %d, Bad Frames %d, Total Frames %d"),
356 goodFrameCount, badFrameCount, badFrameCount+goodFrameCount );
363 * CompareGsm610Frames
364 * This function compares two encoded gsm610 frames
365 * @result TBool Frames are the same or different
368 TBool CTest_MMF_Gsm610::CompareGsm610Frames( TUint8* aGsmFrame,TUint8* aRefGsmFrame )
370 TBool result = ETrue;
372 __ASSERT_DEBUG(aGsmFrame,Panic(EBadArgument));
373 __ASSERT_DEBUG(aRefGsmFrame,Panic(EBadArgument));
380 UnpackFrame0(&codeBuf0, aGsmFrame );
381 UnpackFrame1(&codeBuf1, aGsmFrame );
382 UnpackFrame0(&refCodeBuf0, aRefGsmFrame );
383 UnpackFrame1(&refCodeBuf1, aRefGsmFrame );
385 if( !Compare( codeBuf0, refCodeBuf0 ) ||
386 !Compare( codeBuf1, refCodeBuf1) )
389 //LogGsmFrames( codeBuf0, refCodeBuf0 ); // add for debug reasons
390 //LogGsmFrames( codeBuf1, refCodeBuf1 ); // add for debugging reasons
401 * @param aRefGsmFrame
404 void CTest_MMF_Gsm610::LogGsmFrames( codes& aGsmFrame, codes& aRefGsmFrame )
406 //[ print the quantized lar coefficients ]
407 INFO_PRINTF1(_L("Coded Frame:"));
408 LogGsmFrame( aGsmFrame );
409 INFO_PRINTF1(_L("Reference Frame:"));
410 LogGsmFrame( aRefGsmFrame );
416 * prints a GsmFrame to the test log
420 void CTest_MMF_Gsm610::LogGsmFrame ( codes& aFrame )
422 INFO_PRINTF2(_L("LARc[0] = %d"), aFrame.LARc[0]);
423 INFO_PRINTF2(_L("LARc[1] = %d"), aFrame.LARc[1]);
424 INFO_PRINTF2(_L("LARc[2] = %d"), aFrame.LARc[2]);
425 INFO_PRINTF2(_L("LARc[3] = %d"), aFrame.LARc[3]);
426 INFO_PRINTF2(_L("LARc[4] = %d"), aFrame.LARc[4]);
427 INFO_PRINTF2(_L("LARc[5] = %d"), aFrame.LARc[5]);
428 INFO_PRINTF2(_L("LARc[6] = %d"), aFrame.LARc[6]);
429 INFO_PRINTF2(_L("LARc[7] = %d"), aFrame.LARc[7]);
431 //[ for each sub frame print its data ]
432 for( TInt i = 0; i < 4; i++ )
434 INFO_PRINTF2(_L("Nc = %d"), aFrame.sfc[i].Nc);
435 INFO_PRINTF2(_L("bc = %d"), aFrame.sfc[i].bc);
436 INFO_PRINTF2(_L("Mc= %d"), aFrame.sfc[i].Mc);
437 INFO_PRINTF2(_L("xmaxc = %d"), aFrame.sfc[i].xmaxc);
438 INFO_PRINTF2(_L("xMc[0] = %d"), aFrame.sfc[i].xMc[0]);
439 INFO_PRINTF2(_L("xMc[1] = %d"), aFrame.sfc[i].xMc[1]);
440 INFO_PRINTF2(_L("xMc[2] = %d"), aFrame.sfc[i].xMc[2]);
441 INFO_PRINTF2(_L("xMc[3] = %d"), aFrame.sfc[i].xMc[3]);
442 INFO_PRINTF2(_L("xMc[4] = %d"), aFrame.sfc[i].xMc[4]);
443 INFO_PRINTF2(_L("xMc[5] = %d"), aFrame.sfc[i].xMc[5]);
444 INFO_PRINTF2(_L("xMc[6] = %d"), aFrame.sfc[i].xMc[6]);
445 INFO_PRINTF2(_L("xMc[7] = %d"), aFrame.sfc[i].xMc[7]);
446 INFO_PRINTF2(_L("xMc[8] = %d"), aFrame.sfc[i].xMc[8]);
447 INFO_PRINTF2(_L("xMc[9] = %d"), aFrame.sfc[i].xMc[9]);
448 INFO_PRINTF2(_L("xMc[10] = %d"), aFrame.sfc[i].xMc[10]);
449 INFO_PRINTF2(_L("xMc[11] = %d"), aFrame.sfc[i].xMc[11]);
450 INFO_PRINTF2(_L("xMc[12] = %d"), aFrame.sfc[i].xMc[12]);
459 TBool CTest_MMF_Gsm610::Compare( codes& aFrame1, codes& aFrame2 )
461 TBool result = ETrue;
463 if( (aFrame1.LARc[0] != aFrame2.LARc[0] ) ||
464 (aFrame1.LARc[1] != aFrame2.LARc[1] ) ||
465 (aFrame1.LARc[2] != aFrame2.LARc[2] ) ||
466 (aFrame1.LARc[3] != aFrame2.LARc[3] ) ||
467 (aFrame1.LARc[4] != aFrame2.LARc[4] ) ||
468 (aFrame1.LARc[5] != aFrame2.LARc[5] ) ||
469 (aFrame1.LARc[6] != aFrame2.LARc[6] ) ||
470 (aFrame1.LARc[7] != aFrame2.LARc[7] ) )
475 for( TInt i = 0; i < 4; i++ )
478 (aFrame1.sfc[i].Nc != aFrame2.sfc[i].Nc) ||
479 (aFrame1.sfc[i].bc != aFrame2.sfc[i].bc) ||
480 (aFrame1.sfc[i].Mc != aFrame2.sfc[i].Mc) ||
481 (aFrame1.sfc[i].xmaxc != aFrame2.sfc[i].xmaxc) ||
482 (aFrame1.sfc[i].xMc[0] != aFrame2.sfc[i].xMc[0]) ||
483 (aFrame1.sfc[i].xMc[1] != aFrame2.sfc[i].xMc[1]) ||
484 (aFrame1.sfc[i].xMc[2] != aFrame2.sfc[i].xMc[2]) ||
485 (aFrame1.sfc[i].xMc[3] != aFrame2.sfc[i].xMc[3]) ||
486 (aFrame1.sfc[i].xMc[4] != aFrame2.sfc[i].xMc[4]) ||
487 (aFrame1.sfc[i].xMc[5] != aFrame2.sfc[i].xMc[5]) ||
488 (aFrame1.sfc[i].xMc[6] != aFrame2.sfc[i].xMc[6]) ||
489 (aFrame1.sfc[i].xMc[7] != aFrame2.sfc[i].xMc[7]) ||
490 (aFrame1.sfc[i].xMc[8] != aFrame2.sfc[i].xMc[8]) ||
491 (aFrame1.sfc[i].xMc[9] != aFrame2.sfc[i].xMc[9]) ||
492 (aFrame1.sfc[i].xMc[10] != aFrame2.sfc[i].xMc[10]) ||
493 (aFrame1.sfc[i].xMc[11] != aFrame2.sfc[i].xMc[11]) ||
494 (aFrame1.sfc[i].xMc[12] != aFrame2.sfc[i].xMc[12]))
505 * CompareCodedResults
508 TBool CTest_MMF_Gsm610::CompareDecodeResults(CMMFDataBuffer* aEncoded, CMMFDataBuffer* aRefFrame )
510 TBool result = ETrue;
512 //[ precondition the buffers are of the same length ]
513 __ASSERT_DEBUG(aEncoded,Panic(EBadArgument));
514 __ASSERT_DEBUG(aRefFrame,Panic(EBadArgument));
515 __ASSERT_DEBUG(aEncoded->Data().MaxLength() == aRefFrame->Data().MaxLength(),Panic(EBadArgument));
517 TUint8 *pResults = CONST_CAST(TUint8*,aEncoded->Data().Ptr());
518 TUint8 *pRefData = CONST_CAST(TUint8*,aRefFrame->Data().Ptr());
519 TInt numResults = aEncoded->Data().MaxLength();
521 if (Mem::Compare( pResults,numResults,pRefData,numResults)!=0)
531 * Reads entire data file into buffer
534 void CTest_MMF_Gsm610::ReadDataL( CMMFDataBuffer*& aBuffer, const TDesC& aFile1 )
536 TFileName fileName = GetSuite()->DefaultPath();
537 fileName.Append(aFile1);
540 User::LeaveIfError(file1.Open(iFs, fileName, EFileShareAny | EFileStream | EFileRead));
541 CleanupClosePushL(file1);
543 User::LeaveIfError(file1.Size(fileSize));
544 aBuffer = CMMFDescriptorBuffer::NewL(fileSize);
545 User::LeaveIfError(file1.Read( aBuffer->Data(),fileSize));
546 CleanupStack::PopAndDestroy(1); //file1
556 void CTest_MMF_Gsm610::OpenFileL( RFile& aFile, const TDesC& aFileName )
558 User::LeaveIfError(aFile.Open(iFs, aFileName, EFileShareAny | EFileStream | EFileRead));
567 void CTest_MMF_Gsm610::CloseFileL( RFile& aFile )
576 * assumes file reads sufficient data
579 void CTest_MMF_Gsm610::ReadDataBufferL( const RFile& aFile, CMMFDataBuffer& aBuffer )
581 //[ The read will set the length of the descriptor to the number of bytes read]
582 User::LeaveIfError(aFile.Read( aBuffer.Data(),aBuffer.Data().MaxLength() ));
583 INFO_PRINTF2(_L("Bytes read = %d"), aBuffer.Data().Length() );
590 * Fill a buffer with a sine wave
593 void CTest_MMF_Gsm610::FillPcmBuffer( CMMFDataBuffer& aSrcBuffer )
595 //fill the Src Buffer
596 TUint8* pDst = CONST_CAST(TUint8*,aSrcBuffer.Data().Ptr());
597 TInt length = aSrcBuffer.Data().MaxLength();
603 for(TInt i=0; i<length/2; i++)
605 //[ assign data and place in buffer]
606 theta = KPi*i/5; // fundamental of 800hz sampled @8khz has 20 db or
607 // better reproduction through gsm codec
608 User::LeaveIfError(Math::Sin(val,theta));
609 srcValue = static_cast<TInt16>( 1000 * val );
610 *pDst++ = static_cast<TUint8>( srcValue & KAndMask8bit);
611 *pDst++ = static_cast<TUint8>((srcValue >> 8) & KAndMask8bit );
612 //INFO_PRINTF2(_L("Sine = %d"), srcValue ); //uncomment for debugging purposes
615 aSrcBuffer.Data().SetLength(length);
621 * DoTestStepPostambleL
625 TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepPostambleL(void)
628 CloseFileL( iSrcFile );
629 CloseFileL( iCodedFile );
630 CloseFileL( iDecodeFile );
631 //[ clean up the buffers etc ]
632 delete iRefSrcData; // reference source data
633 delete iRefCodedData; //reference coded data
634 delete iRefDecodedData; // reference decoded data
635 delete iCodedData; // buffer of coded data
636 delete iDecodedData; // buffer of actual decoded data
637 delete iScratchData; // scratch data buffer
648 void CTest_MMF_Gsm610::UnpackFrame0(codes* aCodeBuf, TUint8* pbuf)
650 TInt16* LAR = aCodeBuf->LARc;
652 // unpack the LAR[0..7] from the first 4.5 bytes
653 LAR[0] = (TInt16)((pbuf[0] & 0x3F));
654 LAR[1] = (TInt16)(((pbuf[0] & 0xC0) >> 6) | ((pbuf[1] & 0x0F) << 2));
655 LAR[2] = (TInt16)(((pbuf[1] & 0xF0) >> 4) | ((pbuf[2] & 0x01) << 4));
656 LAR[3] = (TInt16)(((pbuf[2] & 0x3E) >> 1));
657 LAR[4] = (TInt16)(((pbuf[2] & 0xC0) >> 6) | ((pbuf[3] & 0x03) << 2));
658 LAR[5] = (TInt16)(((pbuf[3] & 0x3C) >> 2));
659 LAR[6] = (TInt16)(((pbuf[3] & 0xC0) >> 6) | ((pbuf[4] & 0x01) << 2));
660 LAR[7] = (TInt16)(((pbuf[4] & 0x0E) >> 1));
662 // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
663 for(TInt i = 0; i < 4; i++)
665 struct sfcodes& c = aCodeBuf->sfc[i];
666 #define sfb(x) (pbuf[4+i*7+x])
667 c.Nc = (TInt16)(((sfb(0) & 0xF0) >> 4) | ((sfb(1) & 0x07) << 4));
668 c.bc = (TInt16)(((sfb(1) & 0x18) >> 3));
669 c.Mc = (TInt16)(((sfb(1) & 0x60) >> 5));
670 c.xmaxc = (TInt16)(((sfb(1) & 0x80) >> 7) | ((sfb(2) & 0x1F) << 1));
671 c.xMc[0] = (TInt16)(((sfb(2) & 0xE0) >> 5));
672 c.xMc[1] = (TInt16)((sfb(3) & 0x07));
673 c.xMc[2] = (TInt16)(((sfb(3) & 0x3C) >> 3));
674 c.xMc[3] = (TInt16)(((sfb(3) & 0xC0) >> 6) | ((sfb(4) & 0x01) << 2));
675 c.xMc[4] = (TInt16)(((sfb(4) & 0x0E) >> 1));
676 c.xMc[5] = (TInt16)(((sfb(4) & 0x70) >> 4));
677 c.xMc[6] = (TInt16)(((sfb(4) & 0x80) >> 7) | ((sfb(5) & 0x03) << 1));
678 c.xMc[7] = (TInt16)(((sfb(5) & 0x1C) >> 2));
679 c.xMc[8] = (TInt16)(((sfb(5) & 0xE0) >> 5));
680 c.xMc[9] = (TInt16)((sfb(6) & 0x07));
681 c.xMc[10] = (TInt16)(((sfb(6) & 0x38) >> 3));
682 c.xMc[11] = (TInt16)(((sfb(6) & 0xC0) >> 6) | ((sfb(7) & 0x01) << 2));
683 c.xMc[12] = (TInt16)(((sfb(7) & 0x0E) >> 1));
695 void CTest_MMF_Gsm610::UnpackFrame1(struct codes* aCodeBuf, TUint8* pbuf)
697 TInt16* LAR = aCodeBuf->LARc;
699 // unpack the LAR[0..7] from the first 4.5 bytes
700 LAR[0] = (TInt16)(((pbuf[32] & 0xF0) >> 4) | ((pbuf[33] & 0x03) << 4));
701 LAR[1] = (TInt16)(((pbuf[33] & 0xFC) >> 2));
702 LAR[2] = (TInt16)(((pbuf[34] & 0x1F)));
703 LAR[3] = (TInt16)(((pbuf[34] & 0xE0) >> 5) | ((pbuf[35] & 0x03) << 3));
704 LAR[4] = (TInt16)(((pbuf[35] & 0x3C) >> 2));
705 LAR[5] = (TInt16)(((pbuf[35] & 0xC0) >> 6) | ((pbuf[36] & 0x03) << 2));
706 LAR[6] = (TInt16)(((pbuf[36] & 0x1C) >> 2));
707 LAR[7] = (TInt16)(((pbuf[36] & 0xE0) >> 5));
709 // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
710 for(TInt i = 0; i < 4; i++)
712 struct sfcodes& c = aCodeBuf->sfc[i];
713 #define sfb(x) (pbuf[37+i*7+x])
714 c.Nc = (TInt16)(sfb(0) & 0x7F);
715 c.bc = (TInt16)(((sfb(0) & 0x80) >> 7) | ((sfb(1) & 0x01) << 1));
716 c.Mc = (TInt16)(((sfb(1) & 0x06) >> 1));
717 c.xmaxc = (TInt16)(((sfb(1) & 0xF8) >> 3) | ((sfb(2) & 0x01) << 5));
718 c.xMc[0] = (TInt16)(((sfb(2) & 0x0E) >> 1));
719 c.xMc[1] = (TInt16)(((sfb(2) & 0x70) >> 4));
720 c.xMc[2] = (TInt16)(((sfb(2) & 0x80) >> 7) | ((sfb(3) & 0x03) << 1));
721 c.xMc[3] = (TInt16)(((sfb(3) & 0x1C) >> 2));
722 c.xMc[4] = (TInt16)(((sfb(3) & 0xE0) >> 5));
723 c.xMc[5] = (TInt16)(((sfb(4) & 0x07)));
724 c.xMc[6] = (TInt16)(((sfb(4) & 0x38) >> 3));
725 c.xMc[7] = (TInt16)(((sfb(4) & 0xC0) >> 6) | ((sfb(5) & 0x01) << 2));
726 c.xMc[8] = (TInt16)(((sfb(5) & 0x0E) >> 1));
727 c.xMc[9] = (TInt16)(((sfb(5) & 0x70) >> 4));
728 c.xMc[10] = (TInt16)(((sfb(5) & 0x80) >> 7) | ((sfb(6) & 0x03) << 1));
729 c.xMc[11] = (TInt16)(((sfb(6) & 0x1C) >> 2));
730 c.xMc[12] = (TInt16)(((sfb(6) & 0xE0) >> 5));
739 * Pack the codewords of the even frame into pack buffer.
740 * Packing as in MS gsm610 encoder.
741 * @param aCodeBuf Code words for one speech frame.
742 * @param pbuf the output buffer
745 void CTest_MMF_Gsm610::PackFrame0(struct codes* aCodeBuf, TInt8* pbuf)
747 TInt16* LAR = aCodeBuf->LARc;
749 // pack the LARc[0..7] into the first 4.5 bytes
750 *pbuf++ = (TUint8)(((LAR[0] ) & 0x3F) | ((LAR[1] << 6) & 0xC0));
751 *pbuf++ = (TUint8)(((LAR[1] >> 2) & 0x0F) | ((LAR[2] << 4) & 0xF0));
752 *pbuf++ = (TUint8)(((LAR[2] >> 4) & 0x01) | ((LAR[3] << 1) & 0x3E) | ((LAR[4] << 6) & 0xC0));
753 *pbuf++ = (TUint8)(((LAR[4] >> 2) & 0x03) | ((LAR[5] << 2) & 0x3C) | ((LAR[6] << 6) & 0xC0));
754 *pbuf = (TUint8)(((LAR[6] >> 2) & 0x01) | ((LAR[7] << 1) & 0x0E));
756 // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
757 for(TInt i = 0; i < 4; i++)
759 struct sfcodes& c = aCodeBuf->sfc[i];
760 *pbuf++ |= ((c.Nc << 4) & 0xF0);
761 *pbuf++ = (TUint8)(((c.Nc >> 4) & 0x07) | ((c.bc << 3) & 0x18) | ((c.Mc << 5) & 0x60) | ((c.xmaxc << 7) & 0x80));
762 *pbuf++ = (TUint8)(((c.xmaxc >> 1) & 0x1F) | ((c.xMc[0] << 5) & 0xE0));
763 *pbuf++ = (TUint8)((c.xMc[1] & 0x07) | ((c.xMc[2] << 3) & 0x38) | ((c.xMc[3] << 6) & 0xC0));
764 *pbuf++ = (TUint8)(((c.xMc[3] >> 2) & 0x01) | ((c.xMc[4] << 1) & 0x0E) | ((c.xMc[5] << 4) & 0x70) | ((c.xMc[6] << 7) & 0x80));
765 *pbuf++ = (TUint8)(((c.xMc[6] >> 1) & 0x03) | ((c.xMc[7] << 2) & 0x1C) | ((c.xMc[8] << 5) & 0xE0));
766 *pbuf++ = (TUint8)((c.xMc[9] & 0x07) | ((c.xMc[10] << 3) & 0x38) | ((c.xMc[11] << 6) & 0xC0));
767 *pbuf = (TUint8)(((c.xMc[11] >> 2) & 0x01) | ((c.xMc[12] << 1) & 0x0E));
774 * Pack the codewords of the even frame into pack buffer.
775 * Packing as in MS gsm610 encoder.
776 * @param aCodeBuf Code words for one speech frame.
777 * @param pbuf the output buffer
780 void CTest_MMF_Gsm610::PackFrame1(struct codes* aCodeBuf, TInt8* pbuf)
782 TInt16* LAR = aCodeBuf->LARc;
784 pbuf += (PACKSIZE / 2);
786 // pack the LARc[0..7] into the first 4.5 bytes, starting with the msb of the first byte
787 *pbuf++ = (TUint8) (pbuf[0] | ((LAR[0] << 4) & 0xF0));
788 *pbuf++ = (TUint8)(((LAR[0] >> 4) & 0x03) | ((LAR[1] << 2) & 0xFC));
789 *pbuf++ = (TUint8)(((LAR[2] ) & 0x1F) | ((LAR[3] << 5) & 0xE0));
790 *pbuf++ = (TUint8)(((LAR[3] >> 3) & 0x03) | ((LAR[4] << 2) & 0x3C) | ((LAR[5] << 6) & 0xC0));
791 *pbuf++ = (TUint8)(((LAR[5] >> 2) & 0x03) | ((LAR[6] << 2) & 0x1C) | ((LAR[7] << 5) & 0xE0));
793 // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
794 for(TInt i = 0; i < 4; i++)
796 struct sfcodes& c = aCodeBuf->sfc[i];
797 *pbuf++ = (TUint8)((c.Nc & 0x7F) | ((c.bc << 7) & 0x80));
798 *pbuf++ = (TUint8)(((c.bc >> 1) & 0x01) | ((c.Mc << 1) & 0x06) | ((c.xmaxc << 3) & 0xF8));
799 *pbuf++ = (TUint8)(((c.xmaxc >> 5) & 0x01) | ((c.xMc[0] << 1) & 0x0E) | ((c.xMc[1] << 4) & 0x70) | ((c.xMc[2] << 7) & 0x80));
800 *pbuf++ = (TUint8)(((c.xMc[2] >> 1) & 0x03) | ((c.xMc[3] << 2) & 0x1C) | ((c.xMc[4] << 5) & 0xE0));
801 *pbuf++ = (TUint8)(((c.xMc[5]) & 0x07) | ((c.xMc[6] << 3) & 0x38) | ((c.xMc[7] << 6) & 0xC0));
802 *pbuf++ = (TUint8)(((c.xMc[7] >> 2) & 0x01) | ((c.xMc[8] << 1) & 0x0E) | ((c.xMc[9] << 4) & 0x70) | ((c.xMc[10] << 7) & 0x80));
803 *pbuf++ = (TUint8)(((c.xMc[10] >> 1) & 0x03) | ((c.xMc[11] << 2) & 0x1C) | ((c.xMc[12] << 5) & 0xE0));
809 * CTest_MMF_SwCodecDevices_U_0001
812 CTest_MMF_SwCodecDevices_U_0002::CTest_MMF_SwCodecDevices_U_0002()
814 // store the name of this test case
815 // this is the name that is used by the script file
816 iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0002-HP");
820 * CTest_MMF_SwCodecDevices_U_0001
823 CTest_MMF_SwCodecDevices_U_0002::~CTest_MMF_SwCodecDevices_U_0002()
834 TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepL()
837 TVerdict result = EPass ;
839 CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
840 CleanupStack::PushL(pDecoder);
841 //[ note this reference should be a ptr ]
842 CMMFSwCodec& theCodec = pDecoder->Codec();
844 //[ create buffers of the appropriate size ]
845 const TInt srcBufferSize = theCodec.SourceBufferSize();
846 const TInt sinkBufferSize = theCodec.SinkBufferSize();
847 const TInt codedBufferSize = 76*4* KNumFramesInABuffer; // number of coded buffers * size of coded buffer 63*2
848 iNumCodedFrames = KNumFramesInABuffer; //XXX claculate these constants soon <GK>
850 iScratchData = CMMFDescriptorBuffer::NewL( codedBufferSize);
852 iRefCodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
853 iCodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
854 iRefDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
855 iDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize);
857 //[ for now process only the first buffer ]
859 INFO_PRINTF1(_L("Decoding Frames..."));
860 TInt codedFileSize = 0;
861 iCodedFile.Size( codedFileSize);
863 TInt numBuffers = codedFileSize/srcBufferSize;
866 TInt badBufferCount = 0;
867 TInt goodBufferCount = 0;
868 for( TInt bufferCount = 0; bufferCount < numBuffers; bufferCount++ )
870 ReadDataBufferL(iDecodeFile, *iRefDecodedData );
871 ParseCodedDataL(iCodedData);
873 CMMFSwCodec::TCodecProcessResult decodeRes = theCodec.ProcessL( *iCodedData, *iDecodedData );
874 if( decodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
876 INFO_PRINTF1( _L("Error Failed to complete decoding") );
880 //[ compare results ]
881 if(!CompareDecodeResults( iDecodedData, iRefDecodedData ))
893 //[ log number of good frames & number of bad frames ]
894 INFO_PRINTF4(_L("Good Frames %d, Bad Frames %d, Total Frames %d"),
895 goodBufferCount, badBufferCount, badBufferCount+goodBufferCount );
897 //[pop data from the cleanup stack ]
898 CleanupStack::PopAndDestroy(pDecoder);
900 delete iRefCodedData;
901 iRefCodedData = NULL;
902 delete iRefDecodedData;
903 iRefDecodedData = NULL;
917 * DoTestStepPreambleL
920 enum TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepPreambleL(void)
922 TVerdict result = EPass;
923 //[ connect to the file server ]
924 User::LeaveIfError( iFs.Connect());
926 //[ read the ref source data ]
927 if(!GetStringFromConfig(_L("SectionOne"), _L("SourceData01"), iSourceDataFile) ||
928 !GetStringFromConfig(_L("SectionOne"), _L("CodedData01"), iCodedDataFile) ||
929 !GetStringFromConfig(_L("SectionOne"), _L("DecodedData01"), iDecodedDataFile) )
931 return EInconclusive;
934 //[ open the data files]
935 OpenFileL(iSrcFile,iSourceDataFile );
936 OpenFileL(iCodedFile,iCodedDataFile );
937 OpenFileL(iDecodeFile,iDecodedDataFile);
939 iScratchData = CMMFDescriptorBuffer::NewL(KCodedBufferSize);
946 * DoTestStepPostambleL
950 TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepPostambleL(void)
953 CloseFileL( iCodedFile );
954 CloseFileL( iDecodeFile );
955 //[ clean up the buffers etc ]
956 delete iRefSrcData; // reference source data
957 delete iRefCodedData; //reference coded data
958 delete iRefDecodedData; // refernce decoded data
959 delete iCodedData; // buffer of coded data
960 delete iDecodedData; // buffer of actual decoded data
961 delete iScratchData; // scratch data buffer
967 * CTest_MMF_SwCodecDevices_U_0003
970 CTest_MMF_SwCodecDevices_U_0003::CTest_MMF_SwCodecDevices_U_0003()
972 // store the name of this test case
973 // this is the name that is used by the script file
974 iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0003-HP");
978 * ~CTest_MMF_SwCodecDevices_U_0003
981 CTest_MMF_SwCodecDevices_U_0003::~CTest_MMF_SwCodecDevices_U_0003()
991 TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepL()
994 TVerdict result = EPass ;
996 CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
997 CleanupStack::PushL(pDecoder);
998 //[ note this reference should be a ptr ]
999 CMMFSwCodec& theCodec = pDecoder->Codec();
1001 // do the same for the inverse operation
1002 CMmfPcm16ToGsm610HwDevice* pEncoder = CMmfPcm16ToGsm610HwDevice::NewL();
1003 CleanupStack::PushL(pEncoder);
1004 CMMFSwCodec& theEncode = pEncoder->Codec();
1006 //[ create buffers of the appropriate size ]
1007 const TInt srcBufferSize = theEncode.SourceBufferSize();
1008 const TInt sinkBufferSize = theEncode.SinkBufferSize();
1010 iRefSrcData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1011 iRefCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1012 iRefDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1013 iCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1014 iDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1016 //[ now get a sine wave of 800hz, code and decode and
1017 // compare the results ]
1018 FillPcmBuffer( *iRefSrcData );
1021 CMMFSwCodec::TCodecProcessResult encodeRes = theEncode.ProcessL( *iRefSrcData, *iCodedData );
1022 if( encodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
1024 INFO_PRINTF1( _L("Error Failed to complete coding") );
1029 CMMFSwCodec::TCodecProcessResult decodeRes = theCodec.ProcessL( *iCodedData, *iDecodedData );
1030 if( decodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
1032 INFO_PRINTF1( _L("Error Failed to complete decoding") );
1036 //[ because the codec overwrites its input regenerate it ]
1037 FillPcmBuffer( *iRefSrcData );
1039 //[ NOW COMPARE THE RESULTS DISTORTION < 18 DB ]
1041 TUint8 *pResults = (TUint8*)(iDecodedData->Data().Ptr());
1042 TUint8 *pRefData = (TUint8*)(iRefSrcData->Data().Ptr());
1043 TInt numResults = iDecodedData->Data().MaxLength();
1049 numResults /= 2; // compensate for bytes to short conversion
1050 //[print the results to allow analysis]
1051 for( TInt index = 0; index < numResults; index++ )
1053 temp1 = static_cast<TInt16>((*pResults++) &KAndMask8bit);
1054 temp1 |= static_cast<TInt16>((*pResults++ << 8));
1055 sum1 += temp1*temp1;
1056 temp2 = static_cast<TInt16>((*pRefData++) &KAndMask8bit);
1057 temp2 |= static_cast<TInt16>((*pRefData++ << 8));
1058 sum2 += (temp2-temp1)*(temp2-temp1);
1059 //INFO_PRINTF3( _L("S %d D %d"),temp2, temp1 ); // add for debugging purposes
1062 //[calculate the ratio ]
1066 // calculate as 18db
1067 Math::Log( sn, ratio );
1070 INFO_PRINTF2( _L("Signal to Noise Ratio @800Hz %f db"), sn );
1072 if( sn < 18 ) //[ @800hz a sn of less than 18db is deemed a failure
1073 // not that sn is a great measure of a voice coder's quality]
1076 if( sn < 14 ) //DEF086144 - Codec source buffer size is reduced
1079 //[pop data from the cleanup stack ]
1080 CleanupStack::PopAndDestroy(2, pDecoder); //pDecoder, theCodec,
1083 delete iRefCodedData;
1084 iRefCodedData = NULL;
1085 delete iRefDecodedData;
1086 iRefDecodedData = NULL;
1089 delete iDecodedData;
1090 iDecodedData = NULL;
1099 * DoTestStepPreambleL
1102 TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepPreambleL(void)
1109 * DoTestStepPostambleL
1112 TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepPostambleL(void)
1120 * @param aSrcData pointer to the src data which stores 16bit samples
1121 * @param aNoSamples number of 16bit samples to store
1122 * @param aOffset offset used to generate the samples (linear range)
1124 void TLawUtility::FillSrcBufferL( TUint8* aSrcData, TInt aNoSamples, TInt16 aOffset )
1126 //[precondition aSrcData != NULL ]
1128 User::Leave( KErrArgument );
1129 const TInt16 KUpperLimit = static_cast<TInt16>(aOffset + aNoSamples);
1130 TUint8* pDest = aSrcData ;
1131 for( TInt16 i = aOffset; i< KUpperLimit; i++ )
1133 *pDest++ = static_cast<TUint8>( i & 0xff);
1134 *pDest++ = static_cast<TUint8>( (i >>8) &0xff );
1141 * @param aCodedData the data coded using symbian codec
1142 * @param aRefCodedData the data coded using independent implementation
1143 * @param aNoSamples the number of coded samples
1146 TInt TLawUtility::CompareCodedDataL(TUint8* aCodedData,TUint8* aRefCodedData, TInt aNoSamples )
1148 TInt result = KErrNone;
1149 //[precondition aCodedData != NULL ]
1151 User::Leave( KErrArgument);
1152 //[preciondition aRefCodedData != NULL ]
1153 if( !aRefCodedData )
1154 User::Leave( KErrArgument );
1156 //[ use mem compare to compare the data Buffers ]
1157 if( Mem::Compare(aCodedData, aNoSamples, aRefCodedData, aNoSamples )!=0)
1159 //[ data is not the same ]
1160 for( TInt count = 0; count < aNoSamples; count++ )
1162 //RDebug::Print(_L("c1 %u c2 %u"), *aCodedData++, *aRefCodedData++); Statement commented under DEF105143
1166 result = KErrCorrupt;
1175 * @param aDecodedData
1176 * @return decoded value
1179 TInt16 TLawUtility::AssembleValL(TUint8* aDecodedData)
1183 User::Leave( KErrArgument);
1185 //assemble the value
1186 val = static_cast<TInt16>( aDecodedData[0] &KAndMask8bit);
1187 val |= static_cast<TInt16>((aDecodedData[1] << 8 ));
1197 TReal TLawUtility::SNRatioL(TUint8* aDecodedData, TUint8* aSrcData, TInt aNoSamples )
1199 const TReal KThreshold = 0.0001;
1201 //[precondition aDecodedData != NULL ]
1203 User::Leave( KErrArgument );
1204 //[ precondition aSrcData != NULL ]
1206 User::Leave( KErrArgument );
1208 TReal sumSig = 0.0; // numerator
1209 TReal sumNoise = 0.0; // denominator
1210 TInt difference = 0;
1211 TInt16 dataValue = 0;
1213 for( TInt count = 0; count < aNoSamples; count++ )
1215 decodeVal = AssembleValL(aDecodedData);
1216 dataValue = AssembleValL(aSrcData);
1217 difference = decodeVal - dataValue;
1218 sumSig += (decodeVal*decodeVal); // sum of the squares of the signal
1219 sumNoise += (difference * difference ); // sum of the square of the difference
1224 //[ guard against division by zero ]
1225 if( !( sumNoise >= KThreshold ))
1226 User::Leave( KErrUnderflow );
1228 //[ calculate the sn ratio ]
1229 //[ 10log10( sumSig/SumNoise ]
1230 Math::Log( ratio, (sumSig/sumNoise) );
1231 ratio *= 10; // ratio = 10*log( x**2/(error**2)) in db
1238 * @param aCodecSN codec under test SN ratio in db
1239 * @param aCodecSN2 refernce codec SN ratio in db
1240 * @param aThreshold difference allowed in db
1241 * @result within tolerance
1244 TBool TLawUtility::CompareSNRatiosL( TReal aCodecSN, TReal aCodecSN2, TReal aTolerance )
1246 TBool result = ETrue;
1247 TReal difference = (aCodecSN - aCodecSN2);
1248 //[ it would be nice to replace this with a abs function ?]
1249 if( difference < 0.0 )
1251 if( aTolerance > difference )
1258 if( aTolerance < difference )
1269 * ComputeSNL compute the Signal to Noise Ratio
1272 TReal TLawUtility::ComputeSNL( TReal aSumSigSquared, TReal aSumErrorSquared )
1275 const TReal tolerance = 0.001;
1276 //[precondition error is >= tolerance ]
1277 if( aSumErrorSquared < tolerance )
1278 User::Leave( KErrArgument );
1279 //[claculate ratio safely ]
1280 Math::Log( sn, (aSumSigSquared/aSumErrorSquared));
1290 TReal TLawUtility::SumSquaredL( TUint8* aData, TInt aNoSamples )
1292 //[precondition arg is ok ]
1295 User::Leave(KErrArgument);
1298 TUint8* pData = aData;
1300 TReal sumSigSquared = 0.0;
1301 for( TInt count = 0; count < aNoSamples; count++ )
1303 sample = static_cast<TInt16>( pData[0] &KAndMask8bit);
1304 sample |= static_cast<TInt16>((pData[1] << 8 ));
1305 sumSigSquared += (sample*sample);
1309 return sumSigSquared;
1321 TReal TLawUtility::SumErrorSquaredL( TUint8* aData, TUint8* aData2, TInt aNoSamples )
1323 //[precondition aData is not NULL]
1326 User::Leave(KErrArgument);
1329 //[precondition aData2 is not NULL ]
1332 User::Leave(KErrArgument);
1335 TUint8* pData = aData;
1336 TUint8* pData2 = aData2;
1339 TReal sumErrorSquared = 0.0;
1341 for( TInt count = 0; count < aNoSamples; count++ )
1344 sample = static_cast<TInt16>( pData[0] &KAndMask8bit);
1345 sample |= static_cast<TInt16>((pData[1] << 8 ));
1346 sample2 = static_cast<TInt16>( pData2[0] &KAndMask8bit);
1347 sample2 |= static_cast<TInt16>((pData2[1] << 8 ));
1348 error = sample -sample2; // compute the error
1349 sumErrorSquared += (error*error); // add error squared to the sum
1354 return sumErrorSquared;
1359 * CTestMuLawCodec_U_0006
1362 CTestMuLawCodec_U_0006::CTestMuLawCodec_U_0006()
1365 iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0006-HP");
1370 * LinearToMuLawSample
1371 * @param aSample a 16 bit pcm sample
1372 * @result Mu Law encoded sample
1375 TUint8 CTestMuLawCodec_U_0006::LinearToMuLawSample( TInt16 aSample)
1377 const int KBias = 0x84;
1378 const int KClip = 32635;
1379 TInt sign = (aSample >> 8) & 0x80;
1381 aSample = static_cast<TInt16>(-aSample);
1384 aSample = static_cast<TInt16>(aSample + KBias);
1385 TInt exponent = static_cast<TInt>( MuLawCompressTable[(aSample>>7) & 0xFF]);
1386 TInt mantissa = (aSample >> (exponent+3)) & 0x0F;
1387 TInt compressedByte = ~(sign | (exponent << 4) | mantissa);
1388 return static_cast<TUint8>( compressedByte );
1396 void CTestMuLawCodec_U_0006::ConvertPcmMuLawL(TUint8* aSrcData, TUint8* aCodedData, TInt aNumSamples )
1398 //[ precondition aSrcData ]
1400 User::Leave( KErrArgument );
1401 //[precondition aCodedData ]
1403 User::Leave( KErrArgument );
1405 TUint8* pCoded = aCodedData;
1406 TUint8* pData = aSrcData ;
1408 for( TInt count = 0; count < aNumSamples; count++ )
1411 pcmSample = static_cast<TInt16>(pData[0]);
1412 pcmSample |= static_cast<TInt16>((pData[1] << 8 ));
1413 *pCoded++ = LinearToMuLawSample(pcmSample);
1423 void CTestMuLawCodec_U_0006::ConvertMuLawPcmL(TUint8* aCoded, TUint8* aDecoded, TInt aNumSamples )
1425 //[ precondition aCoded ]
1427 User::Leave( KErrArgument );
1428 //[precondition aDecoded ]
1430 User::Leave( KErrArgument );
1433 TUint8* pCoded = aCoded;
1434 TUint8* pDecoded = aDecoded;
1435 //[ lets convert the data ]
1436 for(TInt count = 0; count < aNumSamples; count++ )
1438 pcmSample = MuLawDecompressTable[*pCoded++];
1439 *pDecoded++ = static_cast<TUint8>( pcmSample & 0xFF);
1440 *pDecoded++ = static_cast<TUint8>((pcmSample >> 8 ) & 0xFF);
1449 TVerdict CTestMuLawCodec_U_0006::DoTestStepL()
1451 TVerdict result = EPass;
1452 const TInt KSrcBufferSize = 400; // small buffer size
1453 const TInt KHalfSrcBufferSize = 200; // small buffer size
1454 const TInt KCodedBufferSize = 200; // small buffer size
1455 const TInt KLowerLimit = -800; //lower limit of test range
1456 const TInt KUpperLimit = 800; // upper limit of test range +1
1458 //[ allocate memory buffers]
1459 TUint8* pSymbianSrcData = new(ELeave)TUint8[KSrcBufferSize];
1460 CleanupStack::PushL(pSymbianSrcData);
1461 TUint8* pIndependentSrcData = new(ELeave)TUint8[KSrcBufferSize];
1462 CleanupStack::PushL(pIndependentSrcData);
1463 TUint8* pSymbianCodedData = new(ELeave)TUint8[KCodedBufferSize];
1464 CleanupStack::PushL(pSymbianCodedData);
1465 TUint8* pIndependentCodedData = new(ELeave)TUint8[KCodedBufferSize];
1466 CleanupStack::PushL(pIndependentCodedData);
1467 TUint8* pSymbianDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1468 CleanupStack::PushL(pSymbianDecodedData);
1469 TUint8* pIndependentDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1470 CleanupStack::PushL(pIndependentDecodedData);
1472 TMMFAudioMuLawToS16PcmCodec decoder;
1473 TMMFAudioSPcm16ToMuLawCodec encoder;
1476 TReal symbianCodecSN = 0.0;
1477 TReal independentCodecSN = 0.0;
1479 TReal sumRefSig = 0.0; // sum of sig squared
1480 TReal sumRefError = 0.0; // sum of error sig squared
1481 TReal sumSymbianSig = 0.0; // sum of sig squared
1482 TReal sumSymbianError = 0.0; // sum of error sig squared
1484 //[ interate over a suitable range and process each buffer]
1485 for( TInt index = KLowerLimit; index < KUpperLimit; index+= KHalfSrcBufferSize )
1487 TInt16 offset = static_cast<TInt16>( index);
1488 //[ fill the src buffers ]
1489 helper.FillSrcBufferL( pSymbianSrcData, KHalfSrcBufferSize, offset );
1490 helper.FillSrcBufferL( pIndependentSrcData, KHalfSrcBufferSize, offset );
1492 //[encode the src data ]
1493 encoder.Convert( pSymbianSrcData, pSymbianCodedData, KHalfSrcBufferSize );
1494 ConvertPcmMuLawL(pIndependentSrcData,pIndependentCodedData,KHalfSrcBufferSize );
1496 //[ decode the data ]
1497 decoder.Convert( pSymbianCodedData, pSymbianDecodedData, KHalfSrcBufferSize );
1498 ConvertMuLawPcmL( pIndependentCodedData,pIndependentDecodedData,KHalfSrcBufferSize);
1500 //[ check both codecs code the data similarly]
1501 TInt errorCode =helper.CompareCodedDataL(pIndependentCodedData, pSymbianCodedData, KHalfSrcBufferSize );
1502 if( errorCode != KErrNone )
1504 INFO_PRINTF1(_L("Forward Transformation for Mu-Law codec is not conformant to ref codec"));
1505 User::LeaveIfError(errorCode);
1507 //[ upate running total sums to be used for signal to noise
1508 // ratio calculations ]
1509 sumRefSig += helper.SumSquaredL(pIndependentSrcData, KHalfSrcBufferSize);
1510 sumRefError += helper.SumErrorSquaredL(pIndependentSrcData,pIndependentDecodedData,KHalfSrcBufferSize);
1511 sumSymbianSig += helper.SumSquaredL(pSymbianSrcData,KHalfSrcBufferSize);
1512 sumSymbianError += helper.SumErrorSquaredL(pSymbianSrcData,pSymbianDecodedData,KHalfSrcBufferSize);
1515 const TReal KTolerance = 1; // allow for a 1 db tolerance
1516 symbianCodecSN = helper.ComputeSNL(sumSymbianSig,sumSymbianError);
1517 independentCodecSN = helper.ComputeSNL(sumRefSig, sumRefError);
1518 // Gamma = (dynamic range of codec /signal std deviation )
1519 INFO_PRINTF1(_L("We would expect S/N ration to be greater than 35db for an MuLaw codec with Gamma = 10"));
1520 INFO_PRINTF2(_L("Signal/Noise Ratio Symbian Codec %f"), symbianCodecSN );
1521 INFO_PRINTF2(_L("Signal/Noise Ratio Reference Codec %f"), independentCodecSN );
1523 //[ compare the s/n ratio's of the two codec implementations]
1524 if( !helper.CompareSNRatiosL( symbianCodecSN, independentCodecSN, KTolerance ))
1526 //[ fail the test because the s/n ratios were divergent ]
1529 CleanupStack::PopAndDestroy(6,pSymbianSrcData); //pSymbianSrcData,pIndependentSrcData,
1530 //pSymbianCodedData,pIndependentCodedData
1531 //pSymbianDecodedData,pIndependentDecodedData
1538 * DoTestStepPreambleL
1541 TVerdict CTestMuLawCodec_U_0006::DoTestStepPreambleL(void)
1543 TVerdict result = EPass;
1544 return result; //nothing doing
1549 * DoTestStepPostambleL
1552 TVerdict CTestMuLawCodec_U_0006::DoTestStepPostambleL(void)
1554 TVerdict result = EPass;
1555 return result; //nothing doing
1560 * Mu-Law Compression Table
1563 const TInt8 CTestMuLawCodec_U_0006::MuLawCompressTable[PcmToMuLawCompressionTableSize] =
1565 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
1566 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1567 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1568 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1569 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1570 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1571 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1572 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1573 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1574 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1575 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1576 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1577 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1578 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1579 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1580 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
1585 * Mu-Law Decompression Table
1588 const TInt16 CTestMuLawCodec_U_0006::MuLawDecompressTable[MuLawToPcmCompressionTableSize]=
1590 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
1591 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
1592 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
1593 -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
1594 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
1595 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
1596 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
1597 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
1598 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
1599 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
1600 -876, -844, -812, -780, -748, -716, -684, -652,
1601 -620, -588, -556, -524, -492, -460, -428, -396,
1602 -372, -356, -340, -324, -308, -292, -276, -260,
1603 -244, -228, -212, -196, -180, -164, -148, -132,
1604 -120, -112, -104, -96, -88, -80, -72, -64,
1605 -56, -48, -40, -32, -24, -16, -8, 0,
1606 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
1607 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
1608 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
1609 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
1610 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
1611 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
1612 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
1613 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
1614 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
1615 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
1616 876, 844, 812, 780, 748, 716, 684, 652,
1617 620, 588, 556, 524, 492, 460, 428, 396,
1618 372, 356, 340, 324, 308, 292, 276, 260,
1619 244, 228, 212, 196, 180, 164, 148, 132,
1620 120, 112, 104, 96, 88, 80, 72, 64,
1621 56, 48, 40, 32, 24, 16, 8, 0
1626 * CTestALawCodec_U_0004
1629 CTestALawCodec_U_0004::CTestALawCodec_U_0004()
1632 iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0004-HP");
1637 * ConvertPcmALaw converts Pcm 16 to 8bit ALaw
1638 * @param aSrcData The src data
1639 * @param aCoded The coded result
1640 * @param aNumSamples The number of samples to be processed
1641 * @precondition aSrcData is not NULL
1642 * @precondition aCodedData is not NULL
1643 * @precondition there is sufficient room in the destination
1644 * to contain the coded samples
1647 void CTestALawCodec_U_0004::ConvertPcmALawL(TUint8* aSrcData, TUint8* aCodedData, TInt aNumSamples )
1649 //[ precondition aSrcData ]
1651 User::Leave( KErrArgument );
1652 //[precondition aCodedData ]
1654 User::Leave( KErrArgument );
1656 TUint8* pCoded = aCodedData;
1657 TUint8* pData = aSrcData ;
1659 for( TInt count = 0; count < aNumSamples; count++ )
1662 pcmSample = static_cast<TInt16>(pData[0]);
1663 pcmSample |= static_cast<TInt16>((pData[1] << 8 ));
1664 *pCoded++ = LinearToALawSample(pcmSample);
1671 * ConvertALawPcm converts from 8bit ALaw to Pcm16
1672 * @param aCoded The coded data
1673 * @param aDecoded The decoded result
1674 * @param aNumSamples The number of samples to be processed
1675 * @precondition aCoded is not NULL
1676 * @precondition aDecoded is not NULL
1677 * @precondition there is sufficient room in the destination
1678 * to contain the coded samples
1681 void CTestALawCodec_U_0004::ConvertALawPcmL(TUint8* aCoded, TUint8* aDecoded, TInt aNumSamples )
1683 //[ precondition aSrcData ]
1685 User::Leave( KErrArgument );
1686 //[precondition aCodedData ]
1688 User::Leave( KErrArgument );
1691 TUint8* pCoded = aCoded;
1692 TUint8* pDecoded = aDecoded;
1693 //[ lets convert the data ]
1694 for(TInt count = 0; count < aNumSamples; count++ )
1696 pcmSample = ALawDecompressTable[*pCoded++];
1697 *pDecoded++ = static_cast<TUint8>(pcmSample & 0xFF);
1698 *pDecoded++ = static_cast<TUint8>((pcmSample >> 8 ) & 0xFF);
1704 * LinearToALawSample converts a Pcm16 sample to ALaw
1705 * @param aSample the PCM 16 sample to be converted
1706 * @result coded result
1709 TUint8 CTestALawCodec_U_0004::LinearToALawSample(TInt16 aSample)
1711 const TInt KClip = 32635;
1715 TUint8 compressedByte;
1716 sign = ((~aSample) >> 8) & 0x80;
1718 aSample = static_cast<TInt16>(-aSample);
1723 exponent = static_cast<TInt>( ALawCompressTable[(aSample >> 8) & 0x7F]);
1724 mantissa = (aSample >> (exponent + 3) ) & 0x0F;
1725 compressedByte = static_cast<TUint8> ((exponent << 4) | mantissa);
1729 compressedByte = static_cast<TUint8> (aSample >> 4);
1731 compressedByte ^= (sign ^ 0x55);
1732 return compressedByte;
1740 TVerdict CTestALawCodec_U_0004::DoTestStepL()
1742 TVerdict result = EPass;
1743 const TInt KSrcBufferSize = 400; // small buffer size
1744 const TInt KHalfSrcBufferSize = 200; // small buffer size
1745 const TInt KCodedBufferSize = 200; // small buffer size
1746 const TInt KLowerLimit = -400; //lower limit of test range
1747 const TInt KUpperLimit = 400; // upper limit of test range +1
1749 //[ allocate memory buffers]
1750 TUint8* pSymbianSrcData = new(ELeave)TUint8[KSrcBufferSize];
1751 CleanupStack::PushL(pSymbianSrcData);
1752 TUint8* pIndependentSrcData = new(ELeave)TUint8[KSrcBufferSize];
1753 CleanupStack::PushL(pIndependentSrcData);
1754 TUint8* pSymbianCodedData = new(ELeave)TUint8[KCodedBufferSize];
1755 CleanupStack::PushL(pSymbianCodedData);
1756 TUint8* pIndependentCodedData = new(ELeave)TUint8[KCodedBufferSize];
1757 CleanupStack::PushL(pIndependentCodedData);
1758 TUint8* pSymbianDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1759 CleanupStack::PushL(pSymbianDecodedData);
1760 TUint8* pIndependentDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1761 CleanupStack::PushL(pIndependentDecodedData);
1763 TMMFAudioSPcm16ToAlawCodec encoder;
1764 TMMFAudioALawToS16PcmCodec decoder;
1767 TReal symbianCodecSN = 0.0;
1768 TReal independentCodecSN = 0.0;
1770 TReal sumRefSig = 0.0; // sum of sig squared
1771 TReal sumRefError = 0.0; // sum of error sig squared
1772 TReal sumSymbianSig = 0.0; // sum of sig squared
1773 TReal sumSymbianError = 0.0; // sum of error sig squared
1775 //[ interate over a suitable range and process each buffer]
1776 for( TInt index = KLowerLimit; index < KUpperLimit; index+= KHalfSrcBufferSize )
1778 TInt16 offset = static_cast<TInt16>( index);
1779 //[ fill the src buffers ]
1780 helper.FillSrcBufferL( pSymbianSrcData, KHalfSrcBufferSize, offset );
1781 helper.FillSrcBufferL( pIndependentSrcData, KHalfSrcBufferSize, offset );
1783 //[encode the src data ]
1784 encoder.Convert( pSymbianSrcData, pSymbianCodedData, KHalfSrcBufferSize );
1785 ConvertPcmALawL(pIndependentSrcData,pIndependentCodedData,KHalfSrcBufferSize );
1787 //[ decode the data ]
1788 decoder.Convert( pSymbianCodedData, pSymbianDecodedData, KHalfSrcBufferSize );
1789 ConvertALawPcmL( pIndependentCodedData,pIndependentDecodedData,KHalfSrcBufferSize);
1791 //[ check both codecs code the data similarly]
1792 TInt errorCode = helper.CompareCodedDataL(pIndependentCodedData, pSymbianCodedData, KHalfSrcBufferSize );
1793 if( errorCode != KErrNone )
1795 INFO_PRINTF1(_L("Forward Transformation for ALaw codec is not conformant to ref codec"));
1796 User::LeaveIfError(errorCode);
1799 //[ upate running total sums to be used for signal to noise
1800 // ratio calculations ]
1801 sumRefSig += helper.SumSquaredL(pIndependentSrcData, KHalfSrcBufferSize);
1802 sumRefError += helper.SumErrorSquaredL(pIndependentSrcData,pIndependentDecodedData,KHalfSrcBufferSize);
1803 sumSymbianSig += helper.SumSquaredL(pSymbianSrcData,KHalfSrcBufferSize);
1804 sumSymbianError += helper.SumErrorSquaredL(pSymbianSrcData,pSymbianDecodedData,KHalfSrcBufferSize);
1806 const TReal KTolerance = 1; // allow for a 1 db tolerance
1807 symbianCodecSN = helper.ComputeSNL(sumSymbianSig,sumSymbianError);
1808 independentCodecSN = helper.ComputeSNL(sumRefSig, sumRefError);
1809 // Gamma = (dynamic range of codec /signal std deviation )
1810 INFO_PRINTF1(_L("We would expect S/N ration to be greater than 30db for an ALaw codec with Gamma = 10"));
1811 INFO_PRINTF2(_L("Signal/Noise Ratio Symbian Codec %f"), symbianCodecSN );
1812 INFO_PRINTF2(_L("Signal/Noise Ratio Reference Codec %f"), independentCodecSN );
1814 //[ compare the s/n ratio's of the two codec implementations]
1815 if( !helper.CompareSNRatiosL( symbianCodecSN, independentCodecSN, KTolerance ))
1817 //[ fail the test because the s/n ratios were divergent ]
1821 CleanupStack::PopAndDestroy(6,pSymbianSrcData); //pSymbianSrcData,pIndependentSrcData,
1822 //pSymbianCodedData,pIndependentCodedData
1823 //pSymbianDecodedData,pIndependentDecodedData
1829 * DoTestStepPreambleL
1832 TVerdict CTestALawCodec_U_0004::DoTestStepPreambleL(void)
1834 TVerdict result = EPass;
1835 return result; //nothing doing
1839 * DoTestStepPostambleL
1842 TVerdict CTestALawCodec_U_0004::DoTestStepPostambleL(void)
1844 TVerdict result = EPass;
1845 return result; //nothing doing
1849 * ALaw Compression Table
1852 const TInt8 CTestALawCodec_U_0004::ALawCompressTable[PcmToALawCompressionTableSize] =
1874 * ALaw Decompression Table
1877 const TInt16 CTestALawCodec_U_0004::ALawDecompressTable[ALawToPcmCompressionTableSize] =
1879 -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
1880 -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
1881 -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
1882 -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
1883 -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,
1884 -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,
1885 -11008,-10496,-12032,-11520,-8960, -8448, -9984, -9472,
1886 -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,
1887 -344, -328, -376, -360, -280, -264, -312, -296,
1888 -472, -456, -504, -488, -408, -392, -440, -424,
1889 -88, -72, -120, -104, -24, -8, -56, -40,
1890 -216, -200, -248, -232, -152, -136, -184, -168,
1891 -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
1892 -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
1893 -688, -656, -752, -720, -560, -528, -624, -592,
1894 -944, -912, -1008, -976, -816, -784, -880, -848,
1895 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
1896 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
1897 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
1898 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
1899 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
1900 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
1901 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
1902 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
1903 344, 328, 376, 360, 280, 264, 312, 296,
1904 472, 456, 504, 488, 408, 392, 440, 424,
1905 88, 72, 120, 104, 24, 8, 56, 40,
1906 216, 200, 248, 232, 152, 136, 184, 168,
1907 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
1908 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
1909 688, 656, 752, 720, 560, 528, 624, 592,
1910 944, 912, 1008, 976, 816, 784, 880, 848
1918 CTestIMaadCodec::CTestIMaadCodec()
1921 iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0022-HP");
1929 TVerdict CTestIMaadCodec::DoTestStepL()
1932 TVerdict result = EPass;
1934 TInt sinkBufferSize;
1935 const TReal KExpectedSNRatioDb = 30.0; //30 db for now
1937 //[ Create coder and decoder codecs ]
1938 CMMFPcm16ToImaAdpcmHwDevice* pHwDevice = CMMFPcm16ToImaAdpcmHwDevice::NewL();
1939 CleanupStack::PushL( pHwDevice );
1941 CMMFSwCodec& theCodec = pHwDevice->Codec();
1943 CMMFImaAdpcmToPcm16CodecHwDevice* pHwDecoder = CMMFImaAdpcmToPcm16CodecHwDevice::NewL();
1944 CleanupStack::PushL( pHwDecoder );
1946 CMMFSwCodec& theDecoder = pHwDecoder->Codec();
1948 //[ Create data buffers with position != 0]
1949 srcBufferSize = 100; // arbitrary non zero size
1950 sinkBufferSize = 100;
1951 CMMFDescriptorBuffer* pSrcBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
1952 CleanupStack::PushL( pSrcBuffer );
1954 CMMFDescriptorBuffer* pSinkBuffer = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1955 CleanupStack::PushL( pSinkBuffer );
1957 //[ trap & check error code ]
1959 pSrcBuffer->Data().SetLength(srcBufferSize);
1960 pSinkBuffer->Data().SetLength(sinkBufferSize);
1961 pSrcBuffer->SetPosition(1);
1962 TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
1963 if( errCode != KErrArgument )
1969 //[set position of sink buffer to nonzero value]
1970 pSrcBuffer->SetPosition(0);
1971 pSinkBuffer->SetPosition(1);
1972 TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
1973 if( errCode != KErrArgument )
1979 //[set position of sink and src to nonzero value ]
1980 pSrcBuffer->SetPosition(1);
1981 pSinkBuffer->SetPosition(1);
1982 TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
1983 if( errCode != KErrArgument )
1989 //[ reset the position of both buffers to zero ]
1990 pSrcBuffer->SetPosition(0);
1991 pSinkBuffer->SetPosition(0);
1992 //[ set the src/sink buffer sizes to src and sink
1993 // buffer sizes and fill src with data ]
1994 CleanupStack::PopAndDestroy(2, pSrcBuffer); // pSrcBuffer, pSinkBuffer
1996 //[Create Source & Sink and fill source data in ]
1997 srcBufferSize = theCodec.SourceBufferSize();
1998 pSrcBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
1999 CleanupStack::PushL( pSrcBuffer );
2001 CMMFDescriptorBuffer* pDecodedBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
2002 CleanupStack::PushL( pDecodedBuffer );
2004 sinkBufferSize = theCodec.SinkBufferSize();
2005 pSinkBuffer = CMMFDescriptorBuffer::NewL( sinkBufferSize );
2006 CleanupStack::PushL( pSinkBuffer );
2008 pSrcBuffer->Data().SetLength(srcBufferSize);
2009 pDecodedBuffer->Data().SetLength(srcBufferSize);
2010 pSinkBuffer->Data().SetLength(sinkBufferSize);
2012 //[ fill src buffer with ramp]
2013 FillSrcBufferL( *pSrcBuffer );
2014 // encode and decode the data
2015 theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer);
2016 theDecoder.ProcessL( *pSinkBuffer, *pDecodedBuffer );
2018 if(!CompareResults( KExpectedSNRatioDb, pSrcBuffer, pDecodedBuffer))
2020 //Test has failed because sn ratio was not good enough
2025 CleanupStack::PopAndDestroy( 5, pHwDevice ); // pHwDevice, pHwDecoder, pSrcBuffer, pDecodedBuffer, pSinkBuffer
2033 * DoTestStepPreambleL
2036 TVerdict CTestIMaadCodec::DoTestStepPreambleL(void)
2043 * DoTestStepPostambleL
2046 TVerdict CTestIMaadCodec::DoTestStepPostambleL(void)
2056 * This function fills the buffer with a ramp of linear pcm16 data
2059 void CTestIMaadCodec::FillSrcBufferL( CMMFDescriptorBuffer& aBuffer )
2062 TInt dataLength = aBuffer.Data().Length();
2063 TUint8* pData = const_cast<TUint8*>(aBuffer.Data().Ptr());
2064 TInt noPc16Samples = dataLength/2;
2065 ASSERT( noPc16Samples*slope < 32768 );
2066 for( TInt16 count = 0; count < noPc16Samples ; count++ )
2068 TInt16 pcmSample = static_cast<TInt16>( count * slope);
2069 *pData++ = static_cast<TUint8>( pcmSample & 0xFF );
2070 *pData++ = static_cast<TUint8>( ( pcmSample >> 8 ));
2077 * @param aExpectedSNRatioDb
2079 * @param aSinkBuffer
2081 * This function returns True if the computed Signal to Noise Ratio
2082 * is Greater than or equal to the expected signal to noise ratio.
2083 * The function will also return EFalse if any of the preconditions
2085 * @precondition aSrcBuffer, aSinkBuffer are not NULL
2086 * @precondition aSrcBuffer data lenegth == aSinkBuffer data length
2087 * @precondition the data buffers contain pcm16 data
2090 TBool CTestIMaadCodec::CompareResults( TReal aExpectedSNRatioDb,
2091 CMMFDescriptorBuffer* aSrcBuffer,
2092 CMMFDescriptorBuffer* aSinkBuffer)
2094 TBool result = EFalse;
2096 //[ precondition pointers are not NULL ]
2097 if( !aSrcBuffer || !aSinkBuffer )
2100 //[ precondition buffer lengths are equal ]
2101 TInt length = aSrcBuffer->Data().Length();
2102 if( length != aSinkBuffer->Data().Length() )
2105 // buffers must be of even length
2106 if( !(length % sizeof(TInt16) == 0 ))
2109 TInt pcmLength = length/2;
2110 TReal sumSignalSquared = 0.0;
2111 TReal sumNoiseSquared = 0.0;
2112 TUint8* pSrcData = const_cast<TUint8*>(aSrcBuffer->Data().Ptr());
2113 TUint8* pDecodeData = const_cast<TUint8*>(aSinkBuffer->Data().Ptr());
2114 TInt16 sampleOriginal;
2115 TInt16 sampleDecode;
2116 for( TInt count = 0; count < pcmLength; count++ )
2118 sampleOriginal = static_cast<TInt16>( pSrcData[0] &KAndMask8bit);
2119 sampleOriginal |= static_cast<TInt16>((pSrcData[1] << 8 ));
2120 sampleDecode = static_cast<TInt16>( pDecodeData[0] &KAndMask8bit);
2121 sampleDecode |= static_cast<TInt16>((pDecodeData[1] << 8 ));
2124 sumSignalSquared += sampleOriginal * sampleOriginal;
2125 TInt noise = sampleOriginal - sampleDecode ;
2126 sumNoiseSquared += noise * noise;
2129 //[ if the noise is low the signals are equivalent and
2130 // overflow can be avoided ]
2131 if( sumNoiseSquared < 0.001 )
2136 TReal computedSNRatioDb;
2137 Math::Log( computedSNRatioDb, sumSignalSquared/sumNoiseSquared );
2138 computedSNRatioDb *= 10;
2140 //[ compare claculated s/n ratio against expected ]
2141 if( computedSNRatioDb >= aExpectedSNRatioDb )