| sl@0 |      1 | // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
 | 
| sl@0 |      2 | // All rights reserved.
 | 
| sl@0 |      3 | // This component and the accompanying materials are made available
 | 
| sl@0 |      4 | // under the terms of "Eclipse Public License v1.0"
 | 
| sl@0 |      5 | // which accompanies this distribution, and is available
 | 
| sl@0 |      6 | // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 | 
| sl@0 |      7 | //
 | 
| sl@0 |      8 | // Initial Contributors:
 | 
| sl@0 |      9 | // Nokia Corporation - initial contribution.
 | 
| sl@0 |     10 | //
 | 
| sl@0 |     11 | // Contributors:
 | 
| sl@0 |     12 | //
 | 
| sl@0 |     13 | // Description:
 | 
| sl@0 |     14 | //
 | 
| sl@0 |     15 | 
 | 
| sl@0 |     16 | // EPOC includes
 | 
| sl@0 |     17 | #include <e32base.h>
 | 
| sl@0 |     18 | #include <e32math.h>
 | 
| sl@0 |     19 | #include "types.h"
 | 
| sl@0 |     20 | #include "gsm610fr.h"
 | 
| sl@0 |     21 | #include "MMFAudioCodecBase.h"
 | 
| sl@0 |     22 | 
 | 
| sl@0 |     23 | // Test system includes
 | 
| sl@0 |     24 | #include "TSU_MMF_SWCODECDEVICES.h"
 | 
| sl@0 |     25 | #include "TSU_MMF_SwCodecDevices_BufferSizes.h"
 | 
| sl@0 |     26 | #include "TSU_MMF_DeviceSuite.h"
 | 
| sl@0 |     27 | #include "MMFAudioSPcm16ToALawCodec.h"
 | 
| sl@0 |     28 | #include "MMFAudioALawToS16PcmCodec.h"
 | 
| sl@0 |     29 | #include "MMFAudioMuLawToS16PcmCodec.h"
 | 
| sl@0 |     30 | #include "MMFAudioSPcm16ToMuLawCodec.h"
 | 
| sl@0 |     31 | #include "mmfpcm16ToImaAdpcm.h"
 | 
| sl@0 |     32 | #include "MmfImaAdpcmtopcm16hwdevice.h"
 | 
| sl@0 |     33 | #include "GSM610.H"
 | 
| sl@0 |     34 | 
 | 
| sl@0 |     35 | /**
 | 
| sl@0 |     36 | *
 | 
| sl@0 |     37 | * CTestStep_MMF_SwCodecDevices
 | 
| sl@0 |     38 | *
 | 
| sl@0 |     39 | **/
 | 
| sl@0 |     40 | CTestStep_MMF_SwCodecDevices::CTestStep_MMF_SwCodecDevices()
 | 
| sl@0 |     41 | 	{
 | 
| sl@0 |     42 | 	iHeapSize = 300000;
 | 
| sl@0 |     43 | 	}
 | 
| sl@0 |     44 | 
 | 
| sl@0 |     45 | /**
 | 
| sl@0 |     46 | *
 | 
| sl@0 |     47 | * ~CTestStep_MMF_SwCodecDevices
 | 
| sl@0 |     48 | *
 | 
| sl@0 |     49 | */
 | 
| sl@0 |     50 | CTestStep_MMF_SwCodecDevices::~CTestStep_MMF_SwCodecDevices()
 | 
| sl@0 |     51 | 	{
 | 
| sl@0 |     52 | 	}
 | 
| sl@0 |     53 | 
 | 
| sl@0 |     54 | /**
 | 
| sl@0 |     55 | *
 | 
| sl@0 |     56 | * SetSuite
 | 
| sl@0 |     57 | * @param aPtr ref to the test suite
 | 
| sl@0 |     58 | *
 | 
| sl@0 |     59 | **/
 | 
| sl@0 |     60 | void CTestStep_MMF_SwCodecDevices::SetSuite( CTestSuite_MMF_SwCodecDevices* aPtr )
 | 
| sl@0 |     61 | 	{
 | 
| sl@0 |     62 | 	iRefSuite = aPtr;
 | 
| sl@0 |     63 | 	}
 | 
| sl@0 |     64 | /**
 | 
| sl@0 |     65 | *
 | 
| sl@0 |     66 | * GetSuite 
 | 
| sl@0 |     67 | * @return CTestSuite_MMF_SwCodecDevices*
 | 
| sl@0 |     68 | *
 | 
| sl@0 |     69 | **/
 | 
| sl@0 |     70 | CTestSuite_MMF_SwCodecDevices* CTestStep_MMF_SwCodecDevices::GetSuite()
 | 
| sl@0 |     71 | 	{
 | 
| sl@0 |     72 | 	return iRefSuite;
 | 
| sl@0 |     73 | 	}
 | 
| sl@0 |     74 | /**
 | 
| sl@0 |     75 | *
 | 
| sl@0 |     76 | * CTest_MMF_Gsm610
 | 
| sl@0 |     77 | *
 | 
| sl@0 |     78 | */
 | 
| sl@0 |     79 | CTest_MMF_Gsm610::CTest_MMF_Gsm610()
 | 
| sl@0 |     80 | 	{
 | 
| sl@0 |     81 | 
 | 
| sl@0 |     82 | 	}
 | 
| sl@0 |     83 | 
 | 
| sl@0 |     84 | /**
 | 
| sl@0 |     85 | *
 | 
| sl@0 |     86 | * CTest_MMF_SwCodecDevices_U_0001
 | 
| sl@0 |     87 | *
 | 
| sl@0 |     88 | */
 | 
| sl@0 |     89 | CTest_MMF_SwCodecDevices_U_0001::CTest_MMF_SwCodecDevices_U_0001()
 | 
| sl@0 |     90 | 		{
 | 
| sl@0 |     91 | 		// store the name of this test case
 | 
| sl@0 |     92 | 		// this is the name that is used by the script file
 | 
| sl@0 |     93 | 		iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0001-HP");
 | 
| sl@0 |     94 | 		}
 | 
| sl@0 |     95 | 
 | 
| sl@0 |     96 | /**
 | 
| sl@0 |     97 | *
 | 
| sl@0 |     98 | * CTest_MMF_SwCodecDevices_U_0001
 | 
| sl@0 |     99 | *
 | 
| sl@0 |    100 | **/
 | 
| sl@0 |    101 | CTest_MMF_SwCodecDevices_U_0001::~CTest_MMF_SwCodecDevices_U_0001()
 | 
| sl@0 |    102 | 		{
 | 
| sl@0 |    103 | 
 | 
| sl@0 |    104 | 		}
 | 
| sl@0 |    105 | /**
 | 
| sl@0 |    106 | *
 | 
| sl@0 |    107 | *
 | 
| sl@0 |    108 | * ~CTest_MMF_Gsm610
 | 
| sl@0 |    109 | *
 | 
| sl@0 |    110 | */
 | 
| sl@0 |    111 | CTest_MMF_Gsm610::~CTest_MMF_Gsm610()
 | 
| sl@0 |    112 | 	{
 | 
| sl@0 |    113 |      // nothing to do ..
 | 
| sl@0 |    114 | 	}
 | 
| sl@0 |    115 | 
 | 
| sl@0 |    116 | /**
 | 
| sl@0 |    117 | *
 | 
| sl@0 |    118 | *
 | 
| sl@0 |    119 | * DoTestStepL
 | 
| sl@0 |    120 | *
 | 
| sl@0 |    121 | */
 | 
| sl@0 |    122 | TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepL()
 | 
| sl@0 |    123 | 	{
 | 
| sl@0 |    124 | 	__MM_HEAP_MARK;
 | 
| sl@0 |    125 | 	TVerdict result = EPass ;
 | 
| sl@0 |    126 | 	
 | 
| sl@0 |    127 | 	CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
 | 
| sl@0 |    128 | 	CleanupStack::PushL(pDecoder);
 | 
| sl@0 |    129 | 	   
 | 
| sl@0 |    130 | 	// do the same for the inverse operation
 | 
| sl@0 |    131 | 	CMmfPcm16ToGsm610HwDevice* pEncoder = CMmfPcm16ToGsm610HwDevice::NewL();
 | 
| sl@0 |    132 | 	CleanupStack::PushL(pEncoder);
 | 
| sl@0 |    133 | 	CMMFSwCodec& theEncode = pEncoder->Codec();
 | 
| sl@0 |    134 | 	
 | 
| sl@0 |    135 | 	//[ create buffers of the appropriate size ]
 | 
| sl@0 |    136 | 	const TInt srcBufferSize   = theEncode.SourceBufferSize();
 | 
| sl@0 |    137 | 	const TInt sinkBufferSize  = theEncode.SinkBufferSize();
 | 
| sl@0 |    138 | 	const TInt codedBufferSize = 76*4* KNumFramesInABuffer; // number of coded buffers * size of coded buffer 63*2 
 | 
| sl@0 |    139 | 	iNumCodedFrames =  KNumFramesInABuffer;                                //XXX claculate these constants soon <GK>
 | 
| sl@0 |    140 | 	
 | 
| sl@0 |    141 | 	iScratchData    = CMMFDescriptorBuffer::NewL( codedBufferSize);
 | 
| sl@0 |    142 | 
 | 
| sl@0 |    143 | 	//[ pcm data buffers ]
 | 
| sl@0 |    144 | 	iRefSrcData     = CMMFDescriptorBuffer::NewL( srcBufferSize );      
 | 
| sl@0 |    145 | 	iDecodedData    = CMMFDescriptorBuffer::NewL( srcBufferSize ); 
 | 
| sl@0 |    146 | 
 | 
| sl@0 |    147 | 	//[ coded data buffers ]
 | 
| sl@0 |    148 | 	iRefCodedData   = CMMFDescriptorBuffer::NewL( sinkBufferSize );  
 | 
| sl@0 |    149 | 	iRefDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
 | 
| sl@0 |    150 | 	iCodedData      = CMMFDescriptorBuffer::NewL( sinkBufferSize );
 | 
| sl@0 |    151 | 	
 | 
| sl@0 |    152 | 	//[ for now process only the first few buffers 
 | 
| sl@0 |    153 | 	// and encode the data]
 | 
| sl@0 |    154 | 	INFO_PRINTF1(_L("Encoding Frame..."));
 | 
| sl@0 |    155 | 	TInt srcFileSize = 0;
 | 
| sl@0 |    156 | 	iSrcFile.Size( srcFileSize);
 | 
| sl@0 |    157 | 	TInt buffLen =iRefSrcData->Data().MaxLength();
 | 
| sl@0 |    158 | 	TInt numBuffers = srcFileSize/buffLen;
 | 
| sl@0 |    159 | 	if( numBuffers > 4 )  // [ not all buffers are processed without error
 | 
| sl@0 |    160 | 		// and this is the intention probably of the test sequences]
 | 
| sl@0 |    161 | 		numBuffers = 4;  
 | 
| sl@0 |    162 | 	TInt badBufferCount = 0;
 | 
| sl@0 |    163 | 	TInt goodBufferCount = 0;
 | 
| sl@0 |    164 | 	
 | 
| sl@0 |    165 | 	for( TInt bufferCount = 0; bufferCount < numBuffers; bufferCount++ )
 | 
| sl@0 |    166 | 		{
 | 
| sl@0 |    167 | 		//[precondition pointers are ok]
 | 
| sl@0 |    168 | 		ReadDataBufferL(iSrcFile, *iRefSrcData );
 | 
| sl@0 |    169 | 		
 | 
| sl@0 |    170 | 		ParseCodedDataL(iRefCodedData);
 | 
| sl@0 |    171 | 		
 | 
| sl@0 |    172 | 		CMMFSwCodec::TCodecProcessResult encodeRes = theEncode.ProcessL( *iRefSrcData, *iCodedData );
 | 
| sl@0 |    173 | 		if( encodeRes !=  CMMFSwCodec::TCodecProcessResult::EProcessComplete  )
 | 
| sl@0 |    174 | 			{
 | 
| sl@0 |    175 | 			INFO_PRINTF1( _L("Error Failed to complete coding") );
 | 
| sl@0 |    176 | 			return EFail;               
 | 
| sl@0 |    177 | 			}
 | 
| sl@0 |    178 | 		
 | 
| sl@0 |    179 | 		//[ compare results ]
 | 
| sl@0 |    180 | 		if( !CompareEncodeResults( iCodedData, iRefCodedData ) )
 | 
| sl@0 |    181 | 			{
 | 
| sl@0 |    182 | 			result = EFail;
 | 
| sl@0 |    183 | 			badBufferCount++;
 | 
| sl@0 |    184 | 			}
 | 
| sl@0 |    185 | 		else
 | 
| sl@0 |    186 | 			{
 | 
| sl@0 |    187 | 			goodBufferCount++;
 | 
| sl@0 |    188 | 			}
 | 
| sl@0 |    189 | 			
 | 
| sl@0 |    190 | 		}
 | 
| sl@0 |    191 | 
 | 
| sl@0 |    192 | 	 	//[ log number of good buffers & number of bad buffers ]
 | 
| sl@0 |    193 | 	INFO_PRINTF4(_L("Good Buffers %d, Bad Buffers %d, Total Buffers %d"), 
 | 
| sl@0 |    194 | 		goodBufferCount, badBufferCount, badBufferCount+goodBufferCount );
 | 
| sl@0 |    195 | 
 | 
| sl@0 |    196 | 	 //[pop data from the cleanup stack ]
 | 
| sl@0 |    197 | 	 CleanupStack::PopAndDestroy(2, pDecoder); //pDecoder, theCodec
 | 
| sl@0 |    198 | 
 | 
| sl@0 |    199 | 	 delete iRefSrcData;     // reference source data
 | 
| sl@0 |    200 | 	 iRefSrcData = NULL;
 | 
| sl@0 |    201 | 	 delete iRefCodedData;   //reference coded data
 | 
| sl@0 |    202 | 	 iRefCodedData = NULL;
 | 
| sl@0 |    203 | 	 delete iRefDecodedData; // reference decoded data
 | 
| sl@0 |    204 | 	 iRefDecodedData = NULL;
 | 
| sl@0 |    205 | 	 delete iCodedData;      // buffer of coded data
 | 
| sl@0 |    206 | 	 iCodedData = NULL;
 | 
| sl@0 |    207 | 	 delete iDecodedData;    // buffer of actual decoded data
 | 
| sl@0 |    208 | 	 iDecodedData = NULL;
 | 
| sl@0 |    209 | 	 delete iScratchData;    // scratch data buffer
 | 
| sl@0 |    210 | 	 iScratchData = NULL;
 | 
| sl@0 |    211 | 
 | 
| sl@0 |    212 | 	__MM_HEAP_MARKEND;
 | 
| sl@0 |    213 | 	  
 | 
| sl@0 |    214 |     return result;
 | 
| sl@0 |    215 | 	}
 | 
| sl@0 |    216 | 
 | 
| sl@0 |    217 | /**
 | 
| sl@0 |    218 | *
 | 
| sl@0 |    219 | * ParseCodedDataL
 | 
| sl@0 |    220 | *
 | 
| sl@0 |    221 | */
 | 
| sl@0 |    222 | void  CTest_MMF_Gsm610::ParseCodedDataL( CMMFDataBuffer* aBuffer )
 | 
| sl@0 |    223 | 	{
 | 
| sl@0 |    224 |    	codes frame0;
 | 
| sl@0 |    225 | 	codes frame1;
 | 
| sl@0 |    226 | 
 | 
| sl@0 |    227 | 	//[ read all the coded data into the scratch buffer from reference file ]
 | 
| sl@0 |    228 | 	ReadDataBufferL( iCodedFile, *iScratchData ); 
 | 
| sl@0 |    229 | 	TUint8* dest = const_cast<TUint8*>(aBuffer->Data().Ptr());
 | 
| sl@0 |    230 | 	TUint8* src  = const_cast<TUint8*>(iScratchData->Data().Ptr());
 | 
| sl@0 |    231 | 
 | 
| sl@0 |    232 | 	//[ for all the coded frames parse these frames to proper coded form ]
 | 
| sl@0 |    233 | 	for( TInt count = 0; count < iNumCodedFrames; count++ )
 | 
| sl@0 |    234 | 		{
 | 
| sl@0 |    235 | 		// parse data to frame
 | 
| sl@0 |    236 | 		ParseFrameL( frame0, src );
 | 
| sl@0 |    237 | 		ParseFrameL( frame1, src );		
 | 
| sl@0 |    238 | 		//[ finally pack the two frames into the coded data buffer ]
 | 
| sl@0 |    239 | 		PackFrame0( &frame0, reinterpret_cast<TInt8*>(dest) );
 | 
| sl@0 |    240 | 		PackFrame1( &frame1, reinterpret_cast<TInt8*>(dest) );
 | 
| sl@0 |    241 | 		dest+= KGsmFrameSize;
 | 
| sl@0 |    242 | 		}
 | 
| sl@0 |    243 | 	
 | 
| sl@0 |    244 | 	  aBuffer->Data().SetLength(KGsmFrameSize*iNumCodedFrames);
 | 
| sl@0 |    245 | 	}
 | 
| sl@0 |    246 | /**
 | 
| sl@0 |    247 | *
 | 
| sl@0 |    248 | * ParseFrame
 | 
| sl@0 |    249 | * @param aFrame this stores the gsm frame in an unpacked structure
 | 
| sl@0 |    250 | * @param aBuffer this contains the reference file data as 76 words
 | 
| sl@0 |    251 | *
 | 
| sl@0 |    252 | */
 | 
| sl@0 |    253 | void CTest_MMF_Gsm610::ParseFrameL( struct codes& aFrame, TUint8* &aSrc )
 | 
| sl@0 |    254 | 	{
 | 
| sl@0 |    255 | 	for(TInt i = 0; i < 8; i++ )
 | 
| sl@0 |    256 | 		{
 | 
| sl@0 |    257 | 		aFrame.LARc[i]  = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
 | 
| sl@0 |    258 | 		aFrame.LARc[i] |= static_cast<TInt16>(*aSrc++ << 8 );
 | 
| sl@0 |    259 | 		}
 | 
| sl@0 |    260 | 	
 | 
| sl@0 |    261 | 	for( TInt j = 0; j < 4; j++ )
 | 
| sl@0 |    262 | 		{ 
 | 
| sl@0 |    263 | 		aFrame.sfc[j].Nc  = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
 | 
| sl@0 |    264 | 		aFrame.sfc[j].Nc |= static_cast<TInt16>(*aSrc++ << 8 );
 | 
| sl@0 |    265 | 		aFrame.sfc[j].bc  = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
 | 
| sl@0 |    266 | 		aFrame.sfc[j].bc |= static_cast<TInt16>(*aSrc++ << 8 );
 | 
| sl@0 |    267 | 		aFrame.sfc[j].Mc  = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
 | 
| sl@0 |    268 | 		aFrame.sfc[j].Mc |= static_cast<TInt16>(*aSrc++ << 8 );
 | 
| sl@0 |    269 | 		aFrame.sfc[j].xmaxc  = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
 | 
| sl@0 |    270 | 		aFrame.sfc[j].xmaxc |= static_cast<TInt16>(*aSrc++ << 8 );
 | 
| sl@0 |    271 | 		
 | 
| sl@0 |    272 | 		for( TInt k = 0; k < 13; k++ )
 | 
| sl@0 |    273 | 			{
 | 
| sl@0 |    274 | 			aFrame.sfc[j].xMc[k]  = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
 | 
| sl@0 |    275 | 			aFrame.sfc[j].xMc[k] |= static_cast<TInt16>(*aSrc++ << 8 );
 | 
| sl@0 |    276 | 			}
 | 
| sl@0 |    277 | 		
 | 
| sl@0 |    278 | 		}
 | 
| sl@0 |    279 | 	
 | 
| sl@0 |    280 | 	}
 | 
| sl@0 |    281 |  
 | 
| sl@0 |    282 | /**
 | 
| sl@0 |    283 | *
 | 
| sl@0 |    284 | * DoTestStepPreambleL
 | 
| sl@0 |    285 | *
 | 
| sl@0 |    286 | */
 | 
| sl@0 |    287 | enum TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepPreambleL(void)
 | 
| sl@0 |    288 | 	{
 | 
| sl@0 |    289 | 	TVerdict result = EPass;
 | 
| sl@0 |    290 |     //[ connect to the file server ]
 | 
| sl@0 |    291 | 	User::LeaveIfError( iFs.Connect());
 | 
| sl@0 |    292 | 
 | 
| sl@0 |    293 | 	//[ read the ref source data ]
 | 
| sl@0 |    294 | 	if(!GetStringFromConfig(_L("SectionOne"), _L("SourceData01"), iSourceDataFile) ||
 | 
| sl@0 |    295 | 	   !GetStringFromConfig(_L("SectionOne"), _L("CodedData01"), iCodedDataFile) ||
 | 
| sl@0 |    296 | 	   !GetStringFromConfig(_L("SectionOne"), _L("DecodedData01"), iDecodedDataFile) )
 | 
| sl@0 |    297 | 		{
 | 
| sl@0 |    298 | 		return EInconclusive;
 | 
| sl@0 |    299 | 		}
 | 
| sl@0 |    300 | 
 | 
| sl@0 |    301 | 	//[ open the data files]
 | 
| sl@0 |    302 | 	OpenFileL(iSrcFile,iSourceDataFile );
 | 
| sl@0 |    303 | 	OpenFileL(iCodedFile,iCodedDataFile );
 | 
| sl@0 |    304 | 	OpenFileL(iDecodeFile,iDecodedDataFile);
 | 
| sl@0 |    305 | 	return result;
 | 
| sl@0 |    306 | 	}
 | 
| sl@0 |    307 | 
 | 
| sl@0 |    308 | /**
 | 
| sl@0 |    309 | *
 | 
| sl@0 |    310 | * CompareCodedResults
 | 
| sl@0 |    311 | * @param aEncodedFrame
 | 
| sl@0 |    312 | * @param aRefFrame
 | 
| sl@0 |    313 | * @result TBool
 | 
| sl@0 |    314 | *
 | 
| sl@0 |    315 | */
 | 
| sl@0 |    316 | TBool CTest_MMF_Gsm610::CompareEncodeResults( CMMFDataBuffer* aEncoded, CMMFDataBuffer* aRefFrame )
 | 
| sl@0 |    317 | 	{
 | 
| sl@0 |    318 |     TBool result = ETrue;
 | 
| sl@0 |    319 | 	
 | 
| sl@0 |    320 | 	//[precondition no encoded frames == refframes ]
 | 
| sl@0 |    321 | 	__ASSERT_DEBUG(aEncoded,Panic(EBadArgument));
 | 
| sl@0 |    322 | 	__ASSERT_DEBUG(aRefFrame,Panic(EBadArgument));
 | 
| sl@0 |    323 | 
 | 
| sl@0 |    324 | 	TInt upperLimit = aEncoded->Data().Length()/KGsmFrameSize;
 | 
| sl@0 |    325 | 
 | 
| sl@0 |    326 | 	const CMMFDataBuffer* encoded = STATIC_CAST(const CMMFDataBuffer*, aEncoded);
 | 
| sl@0 |    327 | 	const CMMFDataBuffer* reference = STATIC_CAST(CMMFDataBuffer*, aRefFrame);
 | 
| sl@0 |    328 | 
 | 
| sl@0 |    329 | 	TUint8* pFrames    = CONST_CAST(TUint8*,encoded->Data().Ptr());
 | 
| sl@0 |    330 | 	TUint8* pRefFrames = CONST_CAST(TUint8*,reference->Data().Ptr());
 | 
| sl@0 |    331 | 
 | 
| sl@0 |    332 | 	TInt badFrameCount = 0;
 | 
| sl@0 |    333 | 	TInt goodFrameCount = 0;
 | 
| sl@0 |    334 | 
 | 
| sl@0 |    335 |     //[ for all frames ]
 | 
| sl@0 |    336 |     for( TInt index = 0; index < upperLimit; index++ )
 | 
| sl@0 |    337 | 		{
 | 
| sl@0 |    338 | 	 //[ compare src and ref frame]
 | 
| sl@0 |    339 | 	   if( !CompareGsm610Frames( pFrames, pRefFrames ))
 | 
| sl@0 |    340 | 		   {
 | 
| sl@0 |    341 | 		   result = EFalse;
 | 
| sl@0 |    342 | 		   badFrameCount++;
 | 
| sl@0 |    343 | 		   INFO_PRINTF2(_L("Bad Frame Number: %d"), index );
 | 
| sl@0 |    344 | 		   }
 | 
| sl@0 |    345 | 	   else{
 | 
| sl@0 |    346 | 		   goodFrameCount++;
 | 
| sl@0 |    347 | 		   }
 | 
| sl@0 |    348 | 
 | 
| sl@0 |    349 | 	    //[ increment frame pointers by size of gsmencoded frame  
 | 
| sl@0 |    350 | 	    pFrames    += KGsmFrameSize;
 | 
| sl@0 |    351 | 		pRefFrames += KGsmFrameSize;
 | 
| sl@0 |    352 | 		}
 | 
| sl@0 |    353 | 
 | 
| sl@0 |    354 | 		 	//[ log number of good frames & number of bad frames ]
 | 
| sl@0 |    355 | 	INFO_PRINTF4(_L("Good Frames %d, Bad Frames %d, Total Frames %d"), 
 | 
| sl@0 |    356 | 		goodFrameCount, badFrameCount, badFrameCount+goodFrameCount );
 | 
| sl@0 |    357 | 
 | 
| sl@0 |    358 | 	 return result ;
 | 
| sl@0 |    359 | 	}
 | 
| sl@0 |    360 | 
 | 
| sl@0 |    361 | /**
 | 
| sl@0 |    362 | *
 | 
| sl@0 |    363 | * CompareGsm610Frames
 | 
| sl@0 |    364 | * This function compares two encoded gsm610 frames
 | 
| sl@0 |    365 | * @result TBool Frames are the same or different
 | 
| sl@0 |    366 | *
 | 
| sl@0 |    367 | **/
 | 
| sl@0 |    368 | TBool CTest_MMF_Gsm610::CompareGsm610Frames( TUint8* aGsmFrame,TUint8* aRefGsmFrame )
 | 
| sl@0 |    369 | 	{
 | 
| sl@0 |    370 | 	 TBool result = ETrue;
 | 
| sl@0 |    371 | 	 ASSERT( aGsmFrame );
 | 
| sl@0 |    372 | 	 __ASSERT_DEBUG(aGsmFrame,Panic(EBadArgument));
 | 
| sl@0 |    373 | 	 __ASSERT_DEBUG(aRefGsmFrame,Panic(EBadArgument));
 | 
| sl@0 |    374 | 	 
 | 
| sl@0 |    375 | 	 codes codeBuf0;
 | 
| sl@0 |    376 | 	 codes codeBuf1;
 | 
| sl@0 |    377 | 	 codes refCodeBuf0;
 | 
| sl@0 |    378 | 	 codes refCodeBuf1; 
 | 
| sl@0 |    379 | 
 | 
| sl@0 |    380 | 	 UnpackFrame0(&codeBuf0, aGsmFrame );
 | 
| sl@0 |    381 | 	 UnpackFrame1(&codeBuf1, aGsmFrame );
 | 
| sl@0 |    382 | 	 UnpackFrame0(&refCodeBuf0, aRefGsmFrame );
 | 
| sl@0 |    383 | 	 UnpackFrame1(&refCodeBuf1, aRefGsmFrame );
 | 
| sl@0 |    384 |     
 | 
| sl@0 |    385 | 	if( !Compare( codeBuf0, refCodeBuf0 ) ||
 | 
| sl@0 |    386 | 		!Compare( codeBuf1, refCodeBuf1) )
 | 
| sl@0 |    387 | 
 | 
| sl@0 |    388 | 		{
 | 
| sl@0 |    389 | 		 //LogGsmFrames( codeBuf0, refCodeBuf0 ); // add for debug reasons
 | 
| sl@0 |    390 | 		 //LogGsmFrames( codeBuf1, refCodeBuf1 ); // add for debugging reasons
 | 
| sl@0 |    391 | 		result = EFalse;
 | 
| sl@0 |    392 | 		}
 | 
| sl@0 |    393 | 
 | 
| sl@0 |    394 | 	 return result ;
 | 
| sl@0 |    395 | 	}
 | 
| sl@0 |    396 | 
 | 
| sl@0 |    397 | /**
 | 
| sl@0 |    398 | *
 | 
| sl@0 |    399 | * LogGsmFrames
 | 
| sl@0 |    400 | * @param aGsmFrame
 | 
| sl@0 |    401 | * @param aRefGsmFrame 
 | 
| sl@0 |    402 | *
 | 
| sl@0 |    403 | **/
 | 
| sl@0 |    404 | void  CTest_MMF_Gsm610::LogGsmFrames( codes& aGsmFrame, codes& aRefGsmFrame )
 | 
| sl@0 |    405 | 	{
 | 
| sl@0 |    406 |     //[ print the quantized lar coefficients ]
 | 
| sl@0 |    407 |    	INFO_PRINTF1(_L("Coded Frame:")); 
 | 
| sl@0 |    408 | 	LogGsmFrame( aGsmFrame );
 | 
| sl@0 |    409 | 	INFO_PRINTF1(_L("Reference Frame:")); 
 | 
| sl@0 |    410 | 	LogGsmFrame( aRefGsmFrame );
 | 
| sl@0 |    411 | 	}
 | 
| sl@0 |    412 | 
 | 
| sl@0 |    413 | /**
 | 
| sl@0 |    414 | *
 | 
| sl@0 |    415 | * LogGsmFrame
 | 
| sl@0 |    416 | * prints a GsmFrame to the test log
 | 
| sl@0 |    417 | * @param aFrame 
 | 
| sl@0 |    418 | *
 | 
| sl@0 |    419 | **/
 | 
| sl@0 |    420 | void  CTest_MMF_Gsm610::LogGsmFrame ( codes& aFrame )
 | 
| sl@0 |    421 | 	{
 | 
| sl@0 |    422 | 	INFO_PRINTF2(_L("LARc[0] = %d"), aFrame.LARc[0]); 
 | 
| sl@0 |    423 | 	INFO_PRINTF2(_L("LARc[1] = %d"), aFrame.LARc[1]);
 | 
| sl@0 |    424 | 	INFO_PRINTF2(_L("LARc[2] = %d"), aFrame.LARc[2]);
 | 
| sl@0 |    425 | 	INFO_PRINTF2(_L("LARc[3] = %d"), aFrame.LARc[3]);
 | 
| sl@0 |    426 | 	INFO_PRINTF2(_L("LARc[4] = %d"), aFrame.LARc[4]); 
 | 
| sl@0 |    427 | 	INFO_PRINTF2(_L("LARc[5] = %d"), aFrame.LARc[5]);
 | 
| sl@0 |    428 | 	INFO_PRINTF2(_L("LARc[6] = %d"), aFrame.LARc[6]);
 | 
| sl@0 |    429 | 	INFO_PRINTF2(_L("LARc[7] = %d"), aFrame.LARc[7]);
 | 
| sl@0 |    430 | 
 | 
| sl@0 |    431 | 	//[ for each sub frame print its data ]
 | 
| sl@0 |    432 | 	for( TInt i = 0; i < 4; i++ )
 | 
| sl@0 |    433 | 		{
 | 
| sl@0 |    434 |          INFO_PRINTF2(_L("Nc = %d"), aFrame.sfc[i].Nc); 
 | 
| sl@0 |    435 | 		 INFO_PRINTF2(_L("bc = %d"), aFrame.sfc[i].bc);
 | 
| sl@0 |    436 | 		 INFO_PRINTF2(_L("Mc= %d"), aFrame.sfc[i].Mc);
 | 
| sl@0 |    437 | 		 INFO_PRINTF2(_L("xmaxc = %d"), aFrame.sfc[i].xmaxc);
 | 
| sl@0 |    438 | 		 INFO_PRINTF2(_L("xMc[0] = %d"), aFrame.sfc[i].xMc[0]);
 | 
| sl@0 |    439 | 		 INFO_PRINTF2(_L("xMc[1] = %d"), aFrame.sfc[i].xMc[1]);
 | 
| sl@0 |    440 | 		 INFO_PRINTF2(_L("xMc[2] = %d"), aFrame.sfc[i].xMc[2]);
 | 
| sl@0 |    441 | 		 INFO_PRINTF2(_L("xMc[3] = %d"), aFrame.sfc[i].xMc[3]);
 | 
| sl@0 |    442 | 		 INFO_PRINTF2(_L("xMc[4] = %d"), aFrame.sfc[i].xMc[4]);
 | 
| sl@0 |    443 | 		 INFO_PRINTF2(_L("xMc[5] = %d"), aFrame.sfc[i].xMc[5]);
 | 
| sl@0 |    444 | 		 INFO_PRINTF2(_L("xMc[6] = %d"), aFrame.sfc[i].xMc[6]);
 | 
| sl@0 |    445 | 		 INFO_PRINTF2(_L("xMc[7] = %d"), aFrame.sfc[i].xMc[7]);
 | 
| sl@0 |    446 | 		 INFO_PRINTF2(_L("xMc[8] = %d"), aFrame.sfc[i].xMc[8]);
 | 
| sl@0 |    447 | 		 INFO_PRINTF2(_L("xMc[9] = %d"), aFrame.sfc[i].xMc[9]);
 | 
| sl@0 |    448 | 		 INFO_PRINTF2(_L("xMc[10] = %d"), aFrame.sfc[i].xMc[10]);
 | 
| sl@0 |    449 | 		 INFO_PRINTF2(_L("xMc[11] = %d"), aFrame.sfc[i].xMc[11]);
 | 
| sl@0 |    450 | 		 INFO_PRINTF2(_L("xMc[12] = %d"), aFrame.sfc[i].xMc[12]);
 | 
| sl@0 |    451 | 		}
 | 
| sl@0 |    452 | 	}
 | 
| sl@0 |    453 | 
 | 
| sl@0 |    454 | /**
 | 
| sl@0 |    455 | *
 | 
| sl@0 |    456 | * Compare
 | 
| sl@0 |    457 | *
 | 
| sl@0 |    458 | **/
 | 
| sl@0 |    459 | TBool CTest_MMF_Gsm610::Compare( codes& aFrame1, codes& aFrame2 )
 | 
| sl@0 |    460 | 	{
 | 
| sl@0 |    461 |      TBool result = ETrue;
 | 
| sl@0 |    462 |      
 | 
| sl@0 |    463 | 	if( (aFrame1.LARc[0] != aFrame2.LARc[0] ) ||
 | 
| sl@0 |    464 | 	    (aFrame1.LARc[1] != aFrame2.LARc[1] ) ||
 | 
| sl@0 |    465 | 	    (aFrame1.LARc[2] != aFrame2.LARc[2] ) ||
 | 
| sl@0 |    466 | 	    (aFrame1.LARc[3] != aFrame2.LARc[3] ) ||
 | 
| sl@0 |    467 | 	    (aFrame1.LARc[4] != aFrame2.LARc[4] ) ||
 | 
| sl@0 |    468 | 	    (aFrame1.LARc[5] != aFrame2.LARc[5] ) ||
 | 
| sl@0 |    469 | 	    (aFrame1.LARc[6] != aFrame2.LARc[6] ) ||
 | 
| sl@0 |    470 | 	    (aFrame1.LARc[7] != aFrame2.LARc[7] ) )
 | 
| sl@0 |    471 | 		{
 | 
| sl@0 |    472 | 		result = EFalse;
 | 
| sl@0 |    473 | 		}
 | 
| sl@0 |    474 | 
 | 
| sl@0 |    475 | 	for( TInt i = 0; i < 4; i++ )
 | 
| sl@0 |    476 | 		{
 | 
| sl@0 |    477 | 		if( 
 | 
| sl@0 |    478 |          (aFrame1.sfc[i].Nc !=  aFrame2.sfc[i].Nc) ||
 | 
| sl@0 |    479 | 		 (aFrame1.sfc[i].bc !=  aFrame2.sfc[i].bc) ||
 | 
| sl@0 |    480 | 		 (aFrame1.sfc[i].Mc !=  aFrame2.sfc[i].Mc) ||
 | 
| sl@0 |    481 | 		 (aFrame1.sfc[i].xmaxc !=	 aFrame2.sfc[i].xmaxc) ||
 | 
| sl@0 |    482 | 		 (aFrame1.sfc[i].xMc[0] != aFrame2.sfc[i].xMc[0]) ||
 | 
| sl@0 |    483 | 		 (aFrame1.sfc[i].xMc[1] !=	aFrame2.sfc[i].xMc[1]) ||
 | 
| sl@0 |    484 | 		 (aFrame1.sfc[i].xMc[2] !=	aFrame2.sfc[i].xMc[2]) ||
 | 
| sl@0 |    485 | 		 (aFrame1.sfc[i].xMc[3] !=	aFrame2.sfc[i].xMc[3]) ||
 | 
| sl@0 |    486 | 		 (aFrame1.sfc[i].xMc[4] !=	aFrame2.sfc[i].xMc[4]) ||
 | 
| sl@0 |    487 | 		 (aFrame1.sfc[i].xMc[5] !=	aFrame2.sfc[i].xMc[5]) ||
 | 
| sl@0 |    488 | 		 (aFrame1.sfc[i].xMc[6] !=	aFrame2.sfc[i].xMc[6]) ||
 | 
| sl@0 |    489 | 		 (aFrame1.sfc[i].xMc[7] !=	aFrame2.sfc[i].xMc[7]) ||
 | 
| sl@0 |    490 | 		 (aFrame1.sfc[i].xMc[8] !=	aFrame2.sfc[i].xMc[8]) ||
 | 
| sl@0 |    491 | 		 (aFrame1.sfc[i].xMc[9] !=	aFrame2.sfc[i].xMc[9]) ||
 | 
| sl@0 |    492 | 		 (aFrame1.sfc[i].xMc[10] !=	aFrame2.sfc[i].xMc[10]) ||
 | 
| sl@0 |    493 | 		 (aFrame1.sfc[i].xMc[11] !=	aFrame2.sfc[i].xMc[11]) ||
 | 
| sl@0 |    494 | 		 (aFrame1.sfc[i].xMc[12] !=	aFrame2.sfc[i].xMc[12]))
 | 
| sl@0 |    495 | 			{
 | 
| sl@0 |    496 | 			result = EFail;
 | 
| sl@0 |    497 | 			}
 | 
| sl@0 |    498 | 		}
 | 
| sl@0 |    499 | 
 | 
| sl@0 |    500 | 	 return result;
 | 
| sl@0 |    501 | 	}
 | 
| sl@0 |    502 | 
 | 
| sl@0 |    503 | /**
 | 
| sl@0 |    504 | *
 | 
| sl@0 |    505 | * CompareCodedResults
 | 
| sl@0 |    506 | *
 | 
| sl@0 |    507 | */
 | 
| sl@0 |    508 | TBool CTest_MMF_Gsm610::CompareDecodeResults(CMMFDataBuffer* aEncoded, CMMFDataBuffer* aRefFrame )
 | 
| sl@0 |    509 | 	{
 | 
| sl@0 |    510 |     TBool result = ETrue;
 | 
| sl@0 |    511 | 	
 | 
| sl@0 |    512 |     //[ precondition the buffers are of the same length ]
 | 
| sl@0 |    513 | 	__ASSERT_DEBUG(aEncoded,Panic(EBadArgument));
 | 
| sl@0 |    514 | 	__ASSERT_DEBUG(aRefFrame,Panic(EBadArgument));
 | 
| sl@0 |    515 | 	__ASSERT_DEBUG(aEncoded->Data().MaxLength() == aRefFrame->Data().MaxLength(),Panic(EBadArgument));
 | 
| sl@0 |    516 | 	
 | 
| sl@0 |    517 | 	TUint8 *pResults = CONST_CAST(TUint8*,aEncoded->Data().Ptr());  
 | 
| sl@0 |    518 | 	TUint8 *pRefData = CONST_CAST(TUint8*,aRefFrame->Data().Ptr());
 | 
| sl@0 |    519 | 	TInt numResults  = aEncoded->Data().MaxLength(); 
 | 
| sl@0 |    520 | 
 | 
| sl@0 |    521 |     if (Mem::Compare( pResults,numResults,pRefData,numResults)!=0)
 | 
| sl@0 |    522 |         {
 | 
| sl@0 |    523 | 		result = EFalse;
 | 
| sl@0 |    524 | 		}
 | 
| sl@0 |    525 |   
 | 
| sl@0 |    526 |     return result ;
 | 
| sl@0 |    527 | 	}
 | 
| sl@0 |    528 | /**
 | 
| sl@0 |    529 | *
 | 
| sl@0 |    530 | * ReadDataL
 | 
| sl@0 |    531 | * Reads entire data file into buffer 
 | 
| sl@0 |    532 | *
 | 
| sl@0 |    533 | **/
 | 
| sl@0 |    534 | void CTest_MMF_Gsm610::ReadDataL( CMMFDataBuffer*& aBuffer, const TDesC& aFile1 )
 | 
| sl@0 |    535 | 	{
 | 
| sl@0 |    536 | 	TFileName fileName = GetSuite()->DefaultPath();
 | 
| sl@0 |    537 | 	fileName.Append(aFile1);
 | 
| sl@0 |    538 | 
 | 
| sl@0 |    539 | 	RFile file1;
 | 
| sl@0 |    540 | 	User::LeaveIfError(file1.Open(iFs, fileName, EFileShareAny | EFileStream | EFileRead));
 | 
| sl@0 |    541 | 	CleanupClosePushL(file1);
 | 
| sl@0 |    542 | 	TInt fileSize = 0;
 | 
| sl@0 |    543 | 	User::LeaveIfError(file1.Size(fileSize));
 | 
| sl@0 |    544 | 	aBuffer = CMMFDescriptorBuffer::NewL(fileSize);
 | 
| sl@0 |    545 | 	User::LeaveIfError(file1.Read( aBuffer->Data(),fileSize));
 | 
| sl@0 |    546 | 	CleanupStack::PopAndDestroy(1); //file1
 | 
| sl@0 |    547 | 	}
 | 
| sl@0 |    548 | 
 | 
| sl@0 |    549 | /**
 | 
| sl@0 |    550 | *
 | 
| sl@0 |    551 | * OpenFileL
 | 
| sl@0 |    552 | * @param aFile
 | 
| sl@0 |    553 | * @param aFileName
 | 
| sl@0 |    554 | *
 | 
| sl@0 |    555 | **/
 | 
| sl@0 |    556 | void CTest_MMF_Gsm610::OpenFileL( RFile& aFile, const TDesC& aFileName )
 | 
| sl@0 |    557 | 	{
 | 
| sl@0 |    558 | 	User::LeaveIfError(aFile.Open(iFs, aFileName, EFileShareAny | EFileStream | EFileRead));
 | 
| sl@0 |    559 | 	}
 | 
| sl@0 |    560 | 
 | 
| sl@0 |    561 | /**
 | 
| sl@0 |    562 | *
 | 
| sl@0 |    563 | * CloseFileL
 | 
| sl@0 |    564 | * @param aFile
 | 
| sl@0 |    565 | *
 | 
| sl@0 |    566 | **/
 | 
| sl@0 |    567 | void CTest_MMF_Gsm610::CloseFileL( RFile& aFile )
 | 
| sl@0 |    568 | 	{
 | 
| sl@0 |    569 | 	aFile.Close();
 | 
| sl@0 |    570 | 	}
 | 
| sl@0 |    571 | 
 | 
| sl@0 |    572 | /**
 | 
| sl@0 |    573 | *
 | 
| sl@0 |    574 | * ReadDataBuffer
 | 
| sl@0 |    575 | * @param aFile
 | 
| sl@0 |    576 | * assumes file reads sufficient data
 | 
| sl@0 |    577 | *
 | 
| sl@0 |    578 | **/
 | 
| sl@0 |    579 | void CTest_MMF_Gsm610::ReadDataBufferL( const RFile& aFile, CMMFDataBuffer& aBuffer )
 | 
| sl@0 |    580 | 	{
 | 
| sl@0 |    581 | 	//[ The read will set the length of the descriptor to the number of bytes read]
 | 
| sl@0 |    582 | 	User::LeaveIfError(aFile.Read( aBuffer.Data(),aBuffer.Data().MaxLength() ));
 | 
| sl@0 |    583 | 	INFO_PRINTF2(_L("Bytes read = %d"), aBuffer.Data().Length() );
 | 
| sl@0 |    584 |    	}
 | 
| sl@0 |    585 | 
 | 
| sl@0 |    586 | /**
 | 
| sl@0 |    587 | *
 | 
| sl@0 |    588 | * FillPcmBuffer
 | 
| sl@0 |    589 | * @param aSrcBuffer
 | 
| sl@0 |    590 | * Fill a buffer with a sine wave
 | 
| sl@0 |    591 | *
 | 
| sl@0 |    592 | **/
 | 
| sl@0 |    593 | void CTest_MMF_Gsm610::FillPcmBuffer( CMMFDataBuffer& aSrcBuffer )
 | 
| sl@0 |    594 | 	{
 | 
| sl@0 |    595 | 	//fill the Src Buffer
 | 
| sl@0 |    596 | 	 TUint8* pDst = CONST_CAST(TUint8*,aSrcBuffer.Data().Ptr());
 | 
| sl@0 |    597 | 	 TInt length =  aSrcBuffer.Data().MaxLength();
 | 
| sl@0 |    598 | 
 | 
| sl@0 |    599 | 	 //[encode the data]
 | 
| sl@0 |    600 | 	 TInt16 srcValue = 0;
 | 
| sl@0 |    601 | 	 TReal val   = 0.0;
 | 
| sl@0 |    602 | 	 TReal theta = 0.0; 
 | 
| sl@0 |    603 | 	 for(TInt i=0; i<length/2; i++)
 | 
| sl@0 |    604 | 		 {
 | 
| sl@0 |    605 | 		 //[ assign data and place in buffer]
 | 
| sl@0 |    606 | 		  theta = KPi*i/5; // fundamental of 800hz sampled @8khz has 20 db or
 | 
| sl@0 |    607 | 		                      // better reproduction through gsm codec
 | 
| sl@0 |    608 | 		  User::LeaveIfError(Math::Sin(val,theta));
 | 
| sl@0 |    609 |           srcValue = static_cast<TInt16>( 1000 * val );
 | 
| sl@0 |    610 | 	      *pDst++ = static_cast<TUint8>( srcValue & KAndMask8bit);
 | 
| sl@0 |    611 | 		  *pDst++ = static_cast<TUint8>((srcValue >> 8) & KAndMask8bit );
 | 
| sl@0 |    612 | 		  //INFO_PRINTF2(_L("Sine = %d"), srcValue );  //uncomment for debugging purposes     
 | 
| sl@0 |    613 | 		 }
 | 
| sl@0 |    614 |     
 | 
| sl@0 |    615 | 	 aSrcBuffer.Data().SetLength(length);
 | 
| sl@0 |    616 | 
 | 
| sl@0 |    617 | 	}
 | 
| sl@0 |    618 | 
 | 
| sl@0 |    619 | /**
 | 
| sl@0 |    620 | *
 | 
| sl@0 |    621 | * DoTestStepPostambleL
 | 
| sl@0 |    622 | * @result TVerdict
 | 
| sl@0 |    623 | * 
 | 
| sl@0 |    624 | */
 | 
| sl@0 |    625 | TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepPostambleL(void)
 | 
| sl@0 |    626 | 	{
 | 
| sl@0 |    627 | 	// close files
 | 
| sl@0 |    628 | 	CloseFileL( iSrcFile );
 | 
| sl@0 |    629 | 	CloseFileL( iCodedFile );
 | 
| sl@0 |    630 | 	CloseFileL( iDecodeFile );
 | 
| sl@0 |    631 |     //[ clean up the buffers etc ]
 | 
| sl@0 |    632 | 	delete iRefSrcData;     // reference source data
 | 
| sl@0 |    633 | 	delete iRefCodedData;   //reference coded data
 | 
| sl@0 |    634 | 	delete iRefDecodedData; // reference decoded data
 | 
| sl@0 |    635 | 	delete iCodedData;      // buffer of coded data
 | 
| sl@0 |    636 | 	delete iDecodedData;    // buffer of actual decoded data
 | 
| sl@0 |    637 | 	delete iScratchData;    // scratch data buffer
 | 
| sl@0 |    638 | 	return EPass;
 | 
| sl@0 |    639 | 	}
 | 
| sl@0 |    640 | 
 | 
| sl@0 |    641 | /**
 | 
| sl@0 |    642 | *
 | 
| sl@0 |    643 | * UnpackFrame0
 | 
| sl@0 |    644 | * @param aCodeBuf 
 | 
| sl@0 |    645 | * @param pbuf
 | 
| sl@0 |    646 | *
 | 
| sl@0 |    647 | **/
 | 
| sl@0 |    648 | void CTest_MMF_Gsm610::UnpackFrame0(codes* aCodeBuf,  TUint8* pbuf)
 | 
| sl@0 |    649 |     {
 | 
| sl@0 |    650 |     TInt16* LAR = aCodeBuf->LARc;
 | 
| sl@0 |    651 | 
 | 
| sl@0 |    652 |     // unpack the LAR[0..7] from the first 4.5 bytes
 | 
| sl@0 |    653 |     LAR[0] = (TInt16)((pbuf[0] & 0x3F));
 | 
| sl@0 |    654 |     LAR[1] = (TInt16)(((pbuf[0] & 0xC0) >> 6) | ((pbuf[1] & 0x0F) << 2));
 | 
| sl@0 |    655 |     LAR[2] = (TInt16)(((pbuf[1] & 0xF0) >> 4) | ((pbuf[2] & 0x01) << 4));
 | 
| sl@0 |    656 |     LAR[3] = (TInt16)(((pbuf[2] & 0x3E) >> 1));
 | 
| sl@0 |    657 |     LAR[4] = (TInt16)(((pbuf[2] & 0xC0) >> 6) | ((pbuf[3] & 0x03) << 2));
 | 
| sl@0 |    658 |     LAR[5] = (TInt16)(((pbuf[3] & 0x3C) >> 2));
 | 
| sl@0 |    659 |     LAR[6] = (TInt16)(((pbuf[3] & 0xC0) >> 6) | ((pbuf[4] & 0x01) << 2));
 | 
| sl@0 |    660 |     LAR[7] = (TInt16)(((pbuf[4] & 0x0E) >> 1));
 | 
| sl@0 |    661 | 
 | 
| sl@0 |    662 |     // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
 | 
| sl@0 |    663 |     for(TInt i = 0; i < 4; i++)
 | 
| sl@0 |    664 |         {
 | 
| sl@0 |    665 |         struct sfcodes& c = aCodeBuf->sfc[i];
 | 
| sl@0 |    666 | #define sfb(x) (pbuf[4+i*7+x])
 | 
| sl@0 |    667 |         c.Nc = (TInt16)(((sfb(0) & 0xF0) >> 4) | ((sfb(1) & 0x07) << 4));
 | 
| sl@0 |    668 |         c.bc = (TInt16)(((sfb(1) & 0x18) >> 3));
 | 
| sl@0 |    669 |         c.Mc = (TInt16)(((sfb(1) & 0x60) >> 5));
 | 
| sl@0 |    670 |         c.xmaxc = (TInt16)(((sfb(1) & 0x80) >> 7) | ((sfb(2) & 0x1F) << 1));
 | 
| sl@0 |    671 |         c.xMc[0] = (TInt16)(((sfb(2) & 0xE0) >> 5));
 | 
| sl@0 |    672 |         c.xMc[1] = (TInt16)((sfb(3) & 0x07));
 | 
| sl@0 |    673 |         c.xMc[2] = (TInt16)(((sfb(3) & 0x3C) >> 3));
 | 
| sl@0 |    674 |         c.xMc[3] = (TInt16)(((sfb(3) & 0xC0) >> 6) | ((sfb(4) & 0x01) << 2));
 | 
| sl@0 |    675 |         c.xMc[4] = (TInt16)(((sfb(4) & 0x0E) >> 1));
 | 
| sl@0 |    676 |         c.xMc[5] = (TInt16)(((sfb(4) & 0x70) >> 4));
 | 
| sl@0 |    677 |         c.xMc[6] = (TInt16)(((sfb(4) & 0x80) >> 7) | ((sfb(5) & 0x03) << 1));
 | 
| sl@0 |    678 |         c.xMc[7] = (TInt16)(((sfb(5) & 0x1C) >> 2));
 | 
| sl@0 |    679 |         c.xMc[8] = (TInt16)(((sfb(5) & 0xE0) >> 5));
 | 
| sl@0 |    680 |         c.xMc[9] = (TInt16)((sfb(6) & 0x07));
 | 
| sl@0 |    681 |         c.xMc[10] = (TInt16)(((sfb(6) & 0x38) >> 3));
 | 
| sl@0 |    682 |         c.xMc[11] = (TInt16)(((sfb(6) & 0xC0) >> 6) | ((sfb(7) & 0x01) << 2));
 | 
| sl@0 |    683 |         c.xMc[12] = (TInt16)(((sfb(7) & 0x0E) >> 1));
 | 
| sl@0 |    684 | #undef sfb
 | 
| sl@0 |    685 |         }
 | 
| sl@0 |    686 |     }
 | 
| sl@0 |    687 | 
 | 
| sl@0 |    688 | /**
 | 
| sl@0 |    689 | *
 | 
| sl@0 |    690 | * UnpackFrame1
 | 
| sl@0 |    691 | * @param aCodeBuf 
 | 
| sl@0 |    692 | * @param pbuf
 | 
| sl@0 |    693 | *
 | 
| sl@0 |    694 | **/
 | 
| sl@0 |    695 | void CTest_MMF_Gsm610::UnpackFrame1(struct codes* aCodeBuf, TUint8* pbuf)
 | 
| sl@0 |    696 | {
 | 
| sl@0 |    697 |     TInt16* LAR = aCodeBuf->LARc;
 | 
| sl@0 |    698 | 
 | 
| sl@0 |    699 |     // unpack the LAR[0..7] from the first 4.5 bytes
 | 
| sl@0 |    700 |     LAR[0] = (TInt16)(((pbuf[32] & 0xF0) >> 4) | ((pbuf[33] & 0x03) << 4));
 | 
| sl@0 |    701 |     LAR[1] = (TInt16)(((pbuf[33] & 0xFC) >> 2));
 | 
| sl@0 |    702 |     LAR[2] = (TInt16)(((pbuf[34] & 0x1F)));
 | 
| sl@0 |    703 |     LAR[3] = (TInt16)(((pbuf[34] & 0xE0) >> 5) | ((pbuf[35] & 0x03) << 3));
 | 
| sl@0 |    704 |     LAR[4] = (TInt16)(((pbuf[35] & 0x3C) >> 2));
 | 
| sl@0 |    705 |     LAR[5] = (TInt16)(((pbuf[35] & 0xC0) >> 6) | ((pbuf[36] & 0x03) << 2));
 | 
| sl@0 |    706 |     LAR[6] = (TInt16)(((pbuf[36] & 0x1C) >> 2));
 | 
| sl@0 |    707 |     LAR[7] = (TInt16)(((pbuf[36] & 0xE0) >> 5));
 | 
| sl@0 |    708 | 
 | 
| sl@0 |    709 |     // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
 | 
| sl@0 |    710 |     for(TInt i = 0; i < 4; i++)
 | 
| sl@0 |    711 |         {
 | 
| sl@0 |    712 |         struct sfcodes& c = aCodeBuf->sfc[i];
 | 
| sl@0 |    713 | #define sfb(x) (pbuf[37+i*7+x])
 | 
| sl@0 |    714 |         c.Nc = (TInt16)(sfb(0) & 0x7F);
 | 
| sl@0 |    715 |         c.bc = (TInt16)(((sfb(0) & 0x80) >> 7) | ((sfb(1) & 0x01) << 1));
 | 
| sl@0 |    716 |         c.Mc = (TInt16)(((sfb(1) & 0x06) >> 1));
 | 
| sl@0 |    717 |         c.xmaxc = (TInt16)(((sfb(1) & 0xF8) >> 3) | ((sfb(2) & 0x01) << 5));
 | 
| sl@0 |    718 |         c.xMc[0] = (TInt16)(((sfb(2) & 0x0E) >> 1));
 | 
| sl@0 |    719 |         c.xMc[1] = (TInt16)(((sfb(2) & 0x70) >> 4));
 | 
| sl@0 |    720 |         c.xMc[2] = (TInt16)(((sfb(2) & 0x80) >> 7) | ((sfb(3) & 0x03) << 1));
 | 
| sl@0 |    721 |         c.xMc[3] = (TInt16)(((sfb(3) & 0x1C) >> 2));
 | 
| sl@0 |    722 |         c.xMc[4] = (TInt16)(((sfb(3) & 0xE0) >> 5));
 | 
| sl@0 |    723 |         c.xMc[5] = (TInt16)(((sfb(4) & 0x07)));
 | 
| sl@0 |    724 |         c.xMc[6] = (TInt16)(((sfb(4) & 0x38) >> 3));
 | 
| sl@0 |    725 |         c.xMc[7] = (TInt16)(((sfb(4) & 0xC0) >> 6) | ((sfb(5) & 0x01) << 2));
 | 
| sl@0 |    726 |         c.xMc[8] = (TInt16)(((sfb(5) & 0x0E) >> 1));
 | 
| sl@0 |    727 |         c.xMc[9] = (TInt16)(((sfb(5) & 0x70) >> 4));
 | 
| sl@0 |    728 |         c.xMc[10] = (TInt16)(((sfb(5) & 0x80) >> 7) | ((sfb(6) & 0x03) << 1));
 | 
| sl@0 |    729 |         c.xMc[11] = (TInt16)(((sfb(6) & 0x1C) >> 2));
 | 
| sl@0 |    730 |         c.xMc[12] = (TInt16)(((sfb(6) & 0xE0) >> 5));
 | 
| sl@0 |    731 | 
 | 
| sl@0 |    732 | #undef sfb
 | 
| sl@0 |    733 |         }
 | 
| sl@0 |    734 |     }
 | 
| sl@0 |    735 | 
 | 
| sl@0 |    736 | /**
 | 
| sl@0 |    737 | *
 | 
| sl@0 |    738 | * PackFrame0 
 | 
| sl@0 |    739 | * Pack the codewords of the even frame into pack buffer.
 | 
| sl@0 |    740 | * Packing as in MS gsm610 encoder.
 | 
| sl@0 |    741 | * @param aCodeBuf  Code words for one speech frame.
 | 
| sl@0 |    742 | * @param pbuf the output buffer
 | 
| sl@0 |    743 | *
 | 
| sl@0 |    744 | **/
 | 
| sl@0 |    745 | void CTest_MMF_Gsm610::PackFrame0(struct codes* aCodeBuf, TInt8* pbuf)
 | 
| sl@0 |    746 |     {
 | 
| sl@0 |    747 |     TInt16* LAR = aCodeBuf->LARc;
 | 
| sl@0 |    748 |     
 | 
| sl@0 |    749 |     // pack the LARc[0..7] into the first 4.5 bytes
 | 
| sl@0 |    750 |     *pbuf++ = (TUint8)(((LAR[0]     ) & 0x3F) | ((LAR[1] << 6) & 0xC0));
 | 
| sl@0 |    751 |     *pbuf++ = (TUint8)(((LAR[1] >> 2) & 0x0F) | ((LAR[2] << 4) & 0xF0));
 | 
| sl@0 |    752 |     *pbuf++ = (TUint8)(((LAR[2] >> 4) & 0x01) | ((LAR[3] << 1) & 0x3E) | ((LAR[4] << 6) & 0xC0));
 | 
| sl@0 |    753 |     *pbuf++ = (TUint8)(((LAR[4] >> 2) & 0x03) | ((LAR[5] << 2) & 0x3C) | ((LAR[6] << 6) & 0xC0));
 | 
| sl@0 |    754 |     *pbuf   = (TUint8)(((LAR[6] >> 2) & 0x01) | ((LAR[7] << 1) & 0x0E));
 | 
| sl@0 |    755 |     
 | 
| sl@0 |    756 |     // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
 | 
| sl@0 |    757 |     for(TInt i = 0; i < 4; i++)
 | 
| sl@0 |    758 |         {
 | 
| sl@0 |    759 |         struct sfcodes& c = aCodeBuf->sfc[i];
 | 
| sl@0 |    760 |         *pbuf++ |= ((c.Nc << 4) & 0xF0);
 | 
| sl@0 |    761 |         *pbuf++ = (TUint8)(((c.Nc >> 4) & 0x07) | ((c.bc << 3) & 0x18) | ((c.Mc << 5) & 0x60) | ((c.xmaxc << 7) & 0x80));
 | 
| sl@0 |    762 |         *pbuf++ = (TUint8)(((c.xmaxc >> 1) & 0x1F) | ((c.xMc[0] << 5) & 0xE0));
 | 
| sl@0 |    763 |         *pbuf++ = (TUint8)((c.xMc[1] & 0x07) | ((c.xMc[2] << 3) & 0x38) | ((c.xMc[3] << 6) & 0xC0));
 | 
| sl@0 |    764 |         *pbuf++ = (TUint8)(((c.xMc[3] >> 2) & 0x01) | ((c.xMc[4] << 1) & 0x0E) | ((c.xMc[5] << 4) & 0x70) | ((c.xMc[6] << 7) & 0x80));
 | 
| sl@0 |    765 |         *pbuf++ = (TUint8)(((c.xMc[6] >> 1) & 0x03) | ((c.xMc[7] << 2) & 0x1C) | ((c.xMc[8] << 5) & 0xE0));
 | 
| sl@0 |    766 |         *pbuf++ = (TUint8)((c.xMc[9] & 0x07) | ((c.xMc[10] << 3) & 0x38) | ((c.xMc[11] << 6) & 0xC0));
 | 
| sl@0 |    767 |         *pbuf   = (TUint8)(((c.xMc[11] >> 2) & 0x01) | ((c.xMc[12] << 1) & 0x0E));
 | 
| sl@0 |    768 |         }
 | 
| sl@0 |    769 |     }
 | 
| sl@0 |    770 | 
 | 
| sl@0 |    771 | /**
 | 
| sl@0 |    772 | *
 | 
| sl@0 |    773 | * PackFrame1 
 | 
| sl@0 |    774 | * Pack the codewords of the even frame into pack buffer.
 | 
| sl@0 |    775 | * Packing as in MS gsm610 encoder.
 | 
| sl@0 |    776 | * @param aCodeBuf  Code words for one speech frame.
 | 
| sl@0 |    777 | * @param pbuf the output buffer
 | 
| sl@0 |    778 | *
 | 
| sl@0 |    779 | **/
 | 
| sl@0 |    780 | void CTest_MMF_Gsm610::PackFrame1(struct codes* aCodeBuf, TInt8* pbuf)
 | 
| sl@0 |    781 |     {
 | 
| sl@0 |    782 |     TInt16* LAR = aCodeBuf->LARc;
 | 
| sl@0 |    783 |     
 | 
| sl@0 |    784 | 	pbuf += (PACKSIZE / 2);
 | 
| sl@0 |    785 | 
 | 
| sl@0 |    786 |     // pack the LARc[0..7] into the first 4.5 bytes, starting with the msb of the first byte
 | 
| sl@0 |    787 |     *pbuf++ = (TUint8) (pbuf[0] | ((LAR[0] << 4) & 0xF0));
 | 
| sl@0 |    788 |     *pbuf++ = (TUint8)(((LAR[0] >> 4) & 0x03) | ((LAR[1] << 2) & 0xFC));
 | 
| sl@0 |    789 |     *pbuf++ = (TUint8)(((LAR[2]     ) & 0x1F) | ((LAR[3] << 5) & 0xE0));
 | 
| sl@0 |    790 |     *pbuf++ = (TUint8)(((LAR[3] >> 3) & 0x03) | ((LAR[4] << 2) & 0x3C) | ((LAR[5] << 6) & 0xC0));
 | 
| sl@0 |    791 |     *pbuf++ = (TUint8)(((LAR[5] >> 2) & 0x03) | ((LAR[6] << 2) & 0x1C) | ((LAR[7] << 5) & 0xE0));
 | 
| sl@0 |    792 |     
 | 
| sl@0 |    793 |     // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
 | 
| sl@0 |    794 |     for(TInt i = 0; i < 4; i++)
 | 
| sl@0 |    795 |         {
 | 
| sl@0 |    796 |         struct sfcodes& c = aCodeBuf->sfc[i];
 | 
| sl@0 |    797 |         *pbuf++ = (TUint8)((c.Nc & 0x7F) | ((c.bc << 7) & 0x80));
 | 
| sl@0 |    798 |         *pbuf++ = (TUint8)(((c.bc >> 1) & 0x01) | ((c.Mc << 1) & 0x06) | ((c.xmaxc << 3) & 0xF8));
 | 
| sl@0 |    799 |         *pbuf++ = (TUint8)(((c.xmaxc >> 5) & 0x01) | ((c.xMc[0] << 1) & 0x0E) | ((c.xMc[1] << 4) & 0x70) | ((c.xMc[2] << 7) & 0x80));
 | 
| sl@0 |    800 |         *pbuf++ = (TUint8)(((c.xMc[2] >> 1) & 0x03) | ((c.xMc[3] << 2) & 0x1C) | ((c.xMc[4] << 5) & 0xE0));
 | 
| sl@0 |    801 |         *pbuf++ = (TUint8)(((c.xMc[5]) & 0x07) | ((c.xMc[6] << 3) & 0x38) | ((c.xMc[7] << 6) & 0xC0));
 | 
| sl@0 |    802 |         *pbuf++ = (TUint8)(((c.xMc[7] >> 2) & 0x01) | ((c.xMc[8] << 1) & 0x0E) | ((c.xMc[9] << 4) & 0x70) | ((c.xMc[10] << 7) & 0x80));
 | 
| sl@0 |    803 |         *pbuf++ = (TUint8)(((c.xMc[10] >> 1) & 0x03) | ((c.xMc[11] << 2) & 0x1C) | ((c.xMc[12] << 5) & 0xE0));
 | 
| sl@0 |    804 |         }
 | 
| sl@0 |    805 |     }
 | 
| sl@0 |    806 | 
 | 
| sl@0 |    807 | /**
 | 
| sl@0 |    808 | *
 | 
| sl@0 |    809 | * CTest_MMF_SwCodecDevices_U_0001
 | 
| sl@0 |    810 | *
 | 
| sl@0 |    811 | */
 | 
| sl@0 |    812 | CTest_MMF_SwCodecDevices_U_0002::CTest_MMF_SwCodecDevices_U_0002()
 | 
| sl@0 |    813 | 		{
 | 
| sl@0 |    814 | 		// store the name of this test case
 | 
| sl@0 |    815 | 		// this is the name that is used by the script file
 | 
| sl@0 |    816 | 		iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0002-HP");
 | 
| sl@0 |    817 | 		}
 | 
| sl@0 |    818 | /**
 | 
| sl@0 |    819 | *
 | 
| sl@0 |    820 | * CTest_MMF_SwCodecDevices_U_0001
 | 
| sl@0 |    821 | *
 | 
| sl@0 |    822 | **/
 | 
| sl@0 |    823 | CTest_MMF_SwCodecDevices_U_0002::~CTest_MMF_SwCodecDevices_U_0002()
 | 
| sl@0 |    824 | 		{
 | 
| sl@0 |    825 | 
 | 
| sl@0 |    826 | 		}
 | 
| sl@0 |    827 | 
 | 
| sl@0 |    828 | /**
 | 
| sl@0 |    829 | *
 | 
| sl@0 |    830 | *
 | 
| sl@0 |    831 | * DoTestStepL
 | 
| sl@0 |    832 | *
 | 
| sl@0 |    833 | **/
 | 
| sl@0 |    834 | TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepL()
 | 
| sl@0 |    835 | 	{
 | 
| sl@0 |    836 | 	__MM_HEAP_MARK;
 | 
| sl@0 |    837 | 	TVerdict result = EPass ;
 | 
| sl@0 |    838 | 	
 | 
| sl@0 |    839 | 	 CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
 | 
| sl@0 |    840 |      CleanupStack::PushL(pDecoder);
 | 
| sl@0 |    841 | 	 //[ note this reference should be a ptr ]
 | 
| sl@0 |    842 |      CMMFSwCodec& theCodec = pDecoder->Codec();
 | 
| sl@0 |    843 |  
 | 
| sl@0 |    844 | 	 //[ create buffers of the appropriate size ]
 | 
| sl@0 |    845 | 	 const TInt srcBufferSize  = theCodec.SourceBufferSize();
 | 
| sl@0 |    846 | 	 const TInt sinkBufferSize = theCodec.SinkBufferSize();
 | 
| sl@0 |    847 | 	 const TInt codedBufferSize = 76*4* KNumFramesInABuffer; // number of coded buffers * size of coded buffer 63*2 
 | 
| sl@0 |    848 | 	 iNumCodedFrames =  KNumFramesInABuffer;                                //XXX claculate these constants soon <GK>
 | 
| sl@0 |    849 | 	
 | 
| sl@0 |    850 | 	 iScratchData    = CMMFDescriptorBuffer::NewL( codedBufferSize);
 | 
| sl@0 |    851 | 
 | 
| sl@0 |    852 | 	 iRefCodedData   = CMMFDescriptorBuffer::NewL( srcBufferSize );  
 | 
| sl@0 |    853 | 	 iCodedData      = CMMFDescriptorBuffer::NewL( srcBufferSize );
 | 
| sl@0 |    854 | 	 iRefDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
 | 
| sl@0 |    855 | 	 iDecodedData    = CMMFDescriptorBuffer::NewL( sinkBufferSize); 
 | 
| sl@0 |    856 | 	 
 | 
| sl@0 |    857 | 	 //[ for now process only the first buffer ]
 | 
| sl@0 |    858 | 	 //[encode the data]
 | 
| sl@0 |    859 | 	 INFO_PRINTF1(_L("Decoding Frames..."));
 | 
| sl@0 |    860 | 	 TInt codedFileSize = 0;
 | 
| sl@0 |    861 | 	 iCodedFile.Size( codedFileSize);
 | 
| sl@0 |    862 | 	
 | 
| sl@0 |    863 |      TInt numBuffers = codedFileSize/srcBufferSize;
 | 
| sl@0 |    864 | 	 if(numBuffers > 4 )
 | 
| sl@0 |    865 | 		 numBuffers = 4;
 | 
| sl@0 |    866 | 	 TInt badBufferCount = 0;
 | 
| sl@0 |    867 | 	 TInt goodBufferCount = 0;
 | 
| sl@0 |    868 | 	 for( TInt bufferCount = 0; bufferCount < numBuffers; bufferCount++ )
 | 
| sl@0 |    869 | 		 {
 | 
| sl@0 |    870 | 		 ReadDataBufferL(iDecodeFile, *iRefDecodedData );
 | 
| sl@0 |    871 | 		 ParseCodedDataL(iCodedData);
 | 
| sl@0 |    872 |  
 | 
| sl@0 |    873 | 		 CMMFSwCodec::TCodecProcessResult decodeRes = theCodec.ProcessL( *iCodedData, *iDecodedData );
 | 
| sl@0 |    874 | 		 if( decodeRes !=  CMMFSwCodec::TCodecProcessResult::EProcessComplete  )
 | 
| sl@0 |    875 | 			 {
 | 
| sl@0 |    876 | 			 INFO_PRINTF1( _L("Error Failed to complete decoding") );
 | 
| sl@0 |    877 | 			 return EFail;               
 | 
| sl@0 |    878 | 			 }
 | 
| sl@0 |    879 | 	
 | 
| sl@0 |    880 | 		 //[ compare results ]
 | 
| sl@0 |    881 | 		 if(!CompareDecodeResults( iDecodedData, iRefDecodedData ))
 | 
| sl@0 |    882 | 			 {
 | 
| sl@0 |    883 | 			 result = EFail;
 | 
| sl@0 |    884 | 		     badBufferCount++;
 | 
| sl@0 |    885 | 			 }
 | 
| sl@0 |    886 | 		 else
 | 
| sl@0 |    887 | 			 {
 | 
| sl@0 |    888 | 			 goodBufferCount++;
 | 
| sl@0 |    889 | 			 }
 | 
| sl@0 |    890 | 		
 | 
| sl@0 |    891 | 		 }
 | 
| sl@0 |    892 | 
 | 
| sl@0 |    893 | 	 	//[ log number of good frames & number of bad frames ]
 | 
| sl@0 |    894 | 	INFO_PRINTF4(_L("Good Frames %d, Bad Frames %d, Total Frames %d"), 
 | 
| sl@0 |    895 | 		goodBufferCount, badBufferCount, badBufferCount+goodBufferCount );
 | 
| sl@0 |    896 | 
 | 
| sl@0 |    897 | 	 //[pop data from the cleanup stack ]
 | 
| sl@0 |    898 | 	 CleanupStack::PopAndDestroy(pDecoder); 
 | 
| sl@0 |    899 | 
 | 
| sl@0 |    900 | 	 delete iRefCodedData;
 | 
| sl@0 |    901 | 	 iRefCodedData = NULL;
 | 
| sl@0 |    902 | 	 delete iRefDecodedData;
 | 
| sl@0 |    903 | 	 iRefDecodedData = NULL;
 | 
| sl@0 |    904 | 	 delete iDecodedData; 
 | 
| sl@0 |    905 | 	 iDecodedData = NULL;
 | 
| sl@0 |    906 | 	 delete iCodedData ;
 | 
| sl@0 |    907 | 	 iCodedData = NULL;
 | 
| sl@0 |    908 | 	 delete iScratchData;
 | 
| sl@0 |    909 | 	 iScratchData = NULL;
 | 
| sl@0 |    910 | 
 | 
| sl@0 |    911 | 	__MM_HEAP_MARKEND;                         
 | 
| sl@0 |    912 |     return result;
 | 
| sl@0 |    913 | 	}
 | 
| sl@0 |    914 | 
 | 
| sl@0 |    915 | /**
 | 
| sl@0 |    916 | *
 | 
| sl@0 |    917 | * DoTestStepPreambleL
 | 
| sl@0 |    918 | *
 | 
| sl@0 |    919 | */
 | 
| sl@0 |    920 | enum TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepPreambleL(void)
 | 
| sl@0 |    921 | 	{
 | 
| sl@0 |    922 | 	TVerdict result = EPass;
 | 
| sl@0 |    923 |     //[ connect to the file server ]
 | 
| sl@0 |    924 | 	User::LeaveIfError( iFs.Connect());
 | 
| sl@0 |    925 | 
 | 
| sl@0 |    926 | 	//[ read the ref source data ]
 | 
| sl@0 |    927 | 	if(!GetStringFromConfig(_L("SectionOne"), _L("SourceData01"), iSourceDataFile) ||
 | 
| sl@0 |    928 | 	   !GetStringFromConfig(_L("SectionOne"), _L("CodedData01"), iCodedDataFile) ||
 | 
| sl@0 |    929 | 	   !GetStringFromConfig(_L("SectionOne"), _L("DecodedData01"), iDecodedDataFile) )
 | 
| sl@0 |    930 | 		{
 | 
| sl@0 |    931 | 		return EInconclusive;
 | 
| sl@0 |    932 | 		}
 | 
| sl@0 |    933 | 
 | 
| sl@0 |    934 | 	//[ open the data files]
 | 
| sl@0 |    935 | 	OpenFileL(iSrcFile,iSourceDataFile );
 | 
| sl@0 |    936 | 	OpenFileL(iCodedFile,iCodedDataFile );
 | 
| sl@0 |    937 | 	OpenFileL(iDecodeFile,iDecodedDataFile);
 | 
| sl@0 |    938 | 
 | 
| sl@0 |    939 | 	iScratchData = CMMFDescriptorBuffer::NewL(KCodedBufferSize);
 | 
| sl@0 |    940 | 
 | 
| sl@0 |    941 | 	return result;
 | 
| sl@0 |    942 | 	}
 | 
| sl@0 |    943 | 
 | 
| sl@0 |    944 | /**
 | 
| sl@0 |    945 | *
 | 
| sl@0 |    946 | * DoTestStepPostambleL
 | 
| sl@0 |    947 | * @result TVerdict
 | 
| sl@0 |    948 | * 
 | 
| sl@0 |    949 | */
 | 
| sl@0 |    950 | TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepPostambleL(void)
 | 
| sl@0 |    951 | 	{
 | 
| sl@0 |    952 | 	// close files
 | 
| sl@0 |    953 | 	CloseFileL( iCodedFile );
 | 
| sl@0 |    954 | 	CloseFileL( iDecodeFile );
 | 
| sl@0 |    955 |     //[ clean up the buffers etc ]
 | 
| sl@0 |    956 | 	delete iRefSrcData;     // reference source data
 | 
| sl@0 |    957 | 	delete iRefCodedData;   //reference coded data
 | 
| sl@0 |    958 | 	delete iRefDecodedData; // refernce decoded data
 | 
| sl@0 |    959 | 	delete iCodedData;      // buffer of coded data
 | 
| sl@0 |    960 | 	delete iDecodedData;    // buffer of actual decoded data
 | 
| sl@0 |    961 | 	delete iScratchData;    // scratch data buffer
 | 
| sl@0 |    962 | 	return EPass;
 | 
| sl@0 |    963 | 	}
 | 
| sl@0 |    964 | 
 | 
| sl@0 |    965 | /**
 | 
| sl@0 |    966 | *
 | 
| sl@0 |    967 | * CTest_MMF_SwCodecDevices_U_0003
 | 
| sl@0 |    968 | *
 | 
| sl@0 |    969 | **/
 | 
| sl@0 |    970 | CTest_MMF_SwCodecDevices_U_0003::CTest_MMF_SwCodecDevices_U_0003()
 | 
| sl@0 |    971 | 		{
 | 
| sl@0 |    972 | 		// store the name of this test case
 | 
| sl@0 |    973 | 		// this is the name that is used by the script file
 | 
| sl@0 |    974 | 		iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0003-HP");
 | 
| sl@0 |    975 | 		}
 | 
| sl@0 |    976 | /**
 | 
| sl@0 |    977 | *
 | 
| sl@0 |    978 | * ~CTest_MMF_SwCodecDevices_U_0003
 | 
| sl@0 |    979 | *
 | 
| sl@0 |    980 | **/
 | 
| sl@0 |    981 | CTest_MMF_SwCodecDevices_U_0003::~CTest_MMF_SwCodecDevices_U_0003()
 | 
| sl@0 |    982 | 	{
 | 
| sl@0 |    983 | 
 | 
| sl@0 |    984 | 	}
 | 
| sl@0 |    985 | 
 | 
| sl@0 |    986 | /**
 | 
| sl@0 |    987 | *
 | 
| sl@0 |    988 | * DoTestStepL
 | 
| sl@0 |    989 | *
 | 
| sl@0 |    990 | **/
 | 
| sl@0 |    991 | TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepL()
 | 
| sl@0 |    992 | 	{
 | 
| sl@0 |    993 | 	__MM_HEAP_MARK;
 | 
| sl@0 |    994 | 	TVerdict result = EPass ;
 | 
| sl@0 |    995 | 	
 | 
| sl@0 |    996 | 	 CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
 | 
| sl@0 |    997 |      CleanupStack::PushL(pDecoder);
 | 
| sl@0 |    998 | 	 //[ note this reference should be a ptr ]
 | 
| sl@0 |    999 |      CMMFSwCodec& theCodec = pDecoder->Codec();
 | 
| sl@0 |   1000 |  
 | 
| sl@0 |   1001 | 	 // do the same for the inverse operation
 | 
| sl@0 |   1002 | 	 CMmfPcm16ToGsm610HwDevice* pEncoder = CMmfPcm16ToGsm610HwDevice::NewL();
 | 
| sl@0 |   1003 |      CleanupStack::PushL(pEncoder);
 | 
| sl@0 |   1004 |      CMMFSwCodec& theEncode = pEncoder->Codec();
 | 
| sl@0 |   1005 | 
 | 
| sl@0 |   1006 | 	 //[ create buffers of the appropriate size ]
 | 
| sl@0 |   1007 | 	 const TInt srcBufferSize = theEncode.SourceBufferSize();
 | 
| sl@0 |   1008 | 	 const TInt sinkBufferSize = theEncode.SinkBufferSize();
 | 
| sl@0 |   1009 | 
 | 
| sl@0 |   1010 | 	 iRefSrcData     = CMMFDescriptorBuffer::NewL( srcBufferSize );   
 | 
| sl@0 |   1011 | 	 iRefCodedData   = CMMFDescriptorBuffer::NewL( sinkBufferSize );  
 | 
| sl@0 |   1012 | 	 iRefDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
 | 
| sl@0 |   1013 | 	 iCodedData      = CMMFDescriptorBuffer::NewL( sinkBufferSize );   
 | 
| sl@0 |   1014 | 	 iDecodedData    = CMMFDescriptorBuffer::NewL( srcBufferSize ); 
 | 
| sl@0 |   1015 | 	 
 | 
| sl@0 |   1016 |      //[ now get a sine wave of 800hz, code and decode and
 | 
| sl@0 |   1017 | 	 // compare the results ]
 | 
| sl@0 |   1018 | 	 FillPcmBuffer( *iRefSrcData );
 | 
| sl@0 |   1019 | 
 | 
| sl@0 |   1020 | 	 // encode
 | 
| sl@0 |   1021 | 	CMMFSwCodec::TCodecProcessResult encodeRes = theEncode.ProcessL( *iRefSrcData, *iCodedData );
 | 
| sl@0 |   1022 | 	 if( encodeRes !=  CMMFSwCodec::TCodecProcessResult::EProcessComplete  )
 | 
| sl@0 |   1023 | 		 {
 | 
| sl@0 |   1024 | 		 INFO_PRINTF1( _L("Error Failed to complete coding") );
 | 
| sl@0 |   1025 | 		 return EFail;               
 | 
| sl@0 |   1026 | 		 }
 | 
| sl@0 |   1027 | 
 | 
| sl@0 |   1028 | 	 //decode
 | 
| sl@0 |   1029 | 	 CMMFSwCodec::TCodecProcessResult decodeRes = theCodec.ProcessL( *iCodedData, *iDecodedData );
 | 
| sl@0 |   1030 | 	 if( decodeRes !=  CMMFSwCodec::TCodecProcessResult::EProcessComplete  )
 | 
| sl@0 |   1031 | 		 {
 | 
| sl@0 |   1032 | 		 INFO_PRINTF1( _L("Error Failed to complete decoding") );
 | 
| sl@0 |   1033 | 		 return EFail;               
 | 
| sl@0 |   1034 | 		 }
 | 
| sl@0 |   1035 | 
 | 
| sl@0 |   1036 | 	 //[ because the codec overwrites its input regenerate it ]
 | 
| sl@0 |   1037 | 	 FillPcmBuffer( *iRefSrcData );
 | 
| sl@0 |   1038 | 
 | 
| sl@0 |   1039 |      //[ NOW COMPARE THE RESULTS DISTORTION < 18 DB ]
 | 
| sl@0 |   1040 | 	 
 | 
| sl@0 |   1041 | 	 TUint8 *pResults = (TUint8*)(iDecodedData->Data().Ptr());  
 | 
| sl@0 |   1042 | 	 TUint8 *pRefData = (TUint8*)(iRefSrcData->Data().Ptr());
 | 
| sl@0 |   1043 | 	 TInt numResults  = iDecodedData->Data().MaxLength(); 
 | 
| sl@0 |   1044 | 	 TReal sum1 = 0.0;
 | 
| sl@0 |   1045 | 	 TReal sum2 = 0.0;
 | 
| sl@0 |   1046 | 	 TReal ratio = 0.0;
 | 
| sl@0 |   1047 | 	 TInt16 temp1 = 0;
 | 
| sl@0 |   1048 | 	 TInt16 temp2 = 0;
 | 
| sl@0 |   1049 | 	 numResults /= 2; // compensate for bytes to short conversion
 | 
| sl@0 |   1050 | 	 //[print the results to allow analysis]
 | 
| sl@0 |   1051 | 	 for( TInt index = 0; index < numResults; index++ )
 | 
| sl@0 |   1052 | 		 {
 | 
| sl@0 |   1053 | 		 temp1  = static_cast<TInt16>((*pResults++) &KAndMask8bit);
 | 
| sl@0 |   1054 | 		 temp1 |= static_cast<TInt16>((*pResults++ << 8));
 | 
| sl@0 |   1055 | 		 sum1 += temp1*temp1;
 | 
| sl@0 |   1056 | 		 temp2  = static_cast<TInt16>((*pRefData++) &KAndMask8bit);
 | 
| sl@0 |   1057 | 		 temp2 |= static_cast<TInt16>((*pRefData++ << 8));
 | 
| sl@0 |   1058 | 		 sum2 += (temp2-temp1)*(temp2-temp1);
 | 
| sl@0 |   1059 | 		 //INFO_PRINTF3( _L("S %d D %d"),temp2, temp1 ); // add for debugging purposes
 | 
| sl@0 |   1060 | 		 }
 | 
| sl@0 |   1061 | 
 | 
| sl@0 |   1062 | 	 //[calculate the ratio ]
 | 
| sl@0 |   1063 | 	 ratio = sum1;
 | 
| sl@0 |   1064 | 	 ratio /=sum2;
 | 
| sl@0 |   1065 | 	 TReal sn = 0.0;
 | 
| sl@0 |   1066 | 	 // calculate as 18db
 | 
| sl@0 |   1067 | 	 Math::Log( sn, ratio );
 | 
| sl@0 |   1068 | 	 sn *= 10;
 | 
| sl@0 |   1069 | 
 | 
| sl@0 |   1070 | 	 INFO_PRINTF2( _L("Signal to Noise Ratio @800Hz %f db"), sn );
 | 
| sl@0 |   1071 | #ifdef EABI
 | 
| sl@0 |   1072 | 	 if( sn < 18 ) //[ @800hz a sn of less than 18db is deemed a failure 
 | 
| sl@0 |   1073 | 		           // not that sn is a great measure of a voice coder's quality]
 | 
| sl@0 |   1074 | 		 result = EFail ;
 | 
| sl@0 |   1075 | #else
 | 
| sl@0 |   1076 | 	 if( sn < 14 ) //DEF086144 - Codec source buffer size is reduced
 | 
| sl@0 |   1077 | 		 result = EFail ;
 | 
| sl@0 |   1078 | #endif
 | 
| sl@0 |   1079 | 	 //[pop data from the cleanup stack ]
 | 
| sl@0 |   1080 | 	 CleanupStack::PopAndDestroy(2, pDecoder); //pDecoder, theCodec,
 | 
| sl@0 |   1081 |      delete iRefSrcData;   
 | 
| sl@0 |   1082 | 	 iRefSrcData = NULL;
 | 
| sl@0 |   1083 | 	 delete iRefCodedData;
 | 
| sl@0 |   1084 | 	 iRefCodedData = NULL;
 | 
| sl@0 |   1085 | 	 delete iRefDecodedData;
 | 
| sl@0 |   1086 | 	 iRefDecodedData = NULL;
 | 
| sl@0 |   1087 | 	 delete iCodedData;   
 | 
| sl@0 |   1088 | 	 iCodedData = NULL;
 | 
| sl@0 |   1089 | 	 delete iDecodedData;
 | 
| sl@0 |   1090 | 	 iDecodedData = NULL;
 | 
| sl@0 |   1091 | 	 
 | 
| sl@0 |   1092 | 	__MM_HEAP_MARKEND;
 | 
| sl@0 |   1093 | 
 | 
| sl@0 |   1094 |     return result;
 | 
| sl@0 |   1095 | 	}
 | 
| sl@0 |   1096 | 
 | 
| sl@0 |   1097 | /**
 | 
| sl@0 |   1098 | *
 | 
| sl@0 |   1099 | * DoTestStepPreambleL
 | 
| sl@0 |   1100 | *
 | 
| sl@0 |   1101 | **/
 | 
| sl@0 |   1102 | TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepPreambleL(void)
 | 
| sl@0 |   1103 | 	{
 | 
| sl@0 |   1104 | 	return EPass;
 | 
| sl@0 |   1105 | 	}
 | 
| sl@0 |   1106 | 
 | 
| sl@0 |   1107 | /**
 | 
| sl@0 |   1108 | *
 | 
| sl@0 |   1109 | * DoTestStepPostambleL
 | 
| sl@0 |   1110 | *
 | 
| sl@0 |   1111 | **/
 | 
| sl@0 |   1112 | TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepPostambleL(void)
 | 
| sl@0 |   1113 | 	{
 | 
| sl@0 |   1114 | 	return EPass;
 | 
| sl@0 |   1115 | 	}
 | 
| sl@0 |   1116 | 
 | 
| sl@0 |   1117 | /**
 | 
| sl@0 |   1118 | *
 | 
| sl@0 |   1119 | * FillSrcBufferL
 | 
| sl@0 |   1120 | * @param aSrcData pointer to the src data which stores 16bit samples
 | 
| sl@0 |   1121 | * @param aNoSamples number of 16bit samples to store
 | 
| sl@0 |   1122 | * @param aOffset offset used to generate the samples (linear range)
 | 
| sl@0 |   1123 | **/
 | 
| sl@0 |   1124 | void TLawUtility::FillSrcBufferL( TUint8* aSrcData, TInt aNoSamples, TInt16 aOffset )
 | 
| sl@0 |   1125 | 	{
 | 
| sl@0 |   1126 | 	//[precondition aSrcData != NULL ]
 | 
| sl@0 |   1127 | 	if( !aSrcData )
 | 
| sl@0 |   1128 | 		User::Leave( KErrArgument );
 | 
| sl@0 |   1129 | 	const TInt16 KUpperLimit = static_cast<TInt16>(aOffset + aNoSamples);
 | 
| sl@0 |   1130 | 	TUint8* pDest = aSrcData ;
 | 
| sl@0 |   1131 | 	for( TInt16 i = aOffset; i< KUpperLimit; i++ )
 | 
| sl@0 |   1132 | 		{
 | 
| sl@0 |   1133 | 	     *pDest++ = static_cast<TUint8>( i & 0xff);
 | 
| sl@0 |   1134 | 		 *pDest++ = static_cast<TUint8>( (i >>8) &0xff );
 | 
| sl@0 |   1135 | 		}
 | 
| sl@0 |   1136 | 	}
 | 
| sl@0 |   1137 | 
 | 
| sl@0 |   1138 | /**
 | 
| sl@0 |   1139 | *
 | 
| sl@0 |   1140 | * CompareCodedData
 | 
| sl@0 |   1141 | * @param aCodedData the data coded using symbian codec
 | 
| sl@0 |   1142 | * @param aRefCodedData the data coded using independent implementation
 | 
| sl@0 |   1143 | * @param aNoSamples the number of coded samples
 | 
| sl@0 |   1144 | *
 | 
| sl@0 |   1145 | **/
 | 
| sl@0 |   1146 | TInt TLawUtility::CompareCodedDataL(TUint8* aCodedData,TUint8* aRefCodedData, TInt aNoSamples )
 | 
| sl@0 |   1147 | 	{
 | 
| sl@0 |   1148 | 	TInt result = KErrNone;
 | 
| sl@0 |   1149 | 	//[precondition aCodedData != NULL ]
 | 
| sl@0 |   1150 |      if( !aCodedData )
 | 
| sl@0 |   1151 | 		 User::Leave( KErrArgument);
 | 
| sl@0 |   1152 | 	 //[preciondition aRefCodedData != NULL ]
 | 
| sl@0 |   1153 | 	 if( !aRefCodedData )
 | 
| sl@0 |   1154 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1155 | 
 | 
| sl@0 |   1156 | 	 //[ use mem compare to compare the data Buffers ]
 | 
| sl@0 |   1157 | 	if( Mem::Compare(aCodedData, aNoSamples, aRefCodedData, aNoSamples )!=0)
 | 
| sl@0 |   1158 | 		{
 | 
| sl@0 |   1159 | 		//[ data is not the same ]
 | 
| sl@0 |   1160 | 		for( TInt count = 0; count < aNoSamples; count++ )
 | 
| sl@0 |   1161 | 			{
 | 
| sl@0 |   1162 | 		 //RDebug::Print(_L("c1 %u c2 %u"), *aCodedData++, *aRefCodedData++); Statement commented under DEF105143
 | 
| sl@0 |   1163 | 		      *aCodedData++; 
 | 
| sl@0 |   1164 | 		      *aRefCodedData++; 
 | 
| sl@0 |   1165 | 			}
 | 
| sl@0 |   1166 | 		result = KErrCorrupt;
 | 
| sl@0 |   1167 | 		}
 | 
| sl@0 |   1168 | 
 | 
| sl@0 |   1169 | 	 return result;
 | 
| sl@0 |   1170 | 	}
 | 
| sl@0 |   1171 | 
 | 
| sl@0 |   1172 | /**
 | 
| sl@0 |   1173 | *
 | 
| sl@0 |   1174 | * AssembleValL
 | 
| sl@0 |   1175 | * @param aDecodedData
 | 
| sl@0 |   1176 | * @return decoded value
 | 
| sl@0 |   1177 | *
 | 
| sl@0 |   1178 | **/
 | 
| sl@0 |   1179 | TInt16 TLawUtility::AssembleValL(TUint8* aDecodedData)
 | 
| sl@0 |   1180 | 	{
 | 
| sl@0 |   1181 | 	TInt16 val;
 | 
| sl@0 |   1182 |     if(!aDecodedData )
 | 
| sl@0 |   1183 | 		User::Leave( KErrArgument);
 | 
| sl@0 |   1184 |  
 | 
| sl@0 |   1185 | 	//assemble the value 
 | 
| sl@0 |   1186 | 	val  = static_cast<TInt16>( aDecodedData[0] &KAndMask8bit);  
 | 
| sl@0 |   1187 | 	val |=  static_cast<TInt16>((aDecodedData[1] << 8 ));
 | 
| sl@0 |   1188 | 
 | 
| sl@0 |   1189 | 	return val;
 | 
| sl@0 |   1190 | 	}
 | 
| sl@0 |   1191 | 
 | 
| sl@0 |   1192 | /**
 | 
| sl@0 |   1193 | *
 | 
| sl@0 |   1194 | * SNRatio
 | 
| sl@0 |   1195 | *
 | 
| sl@0 |   1196 | **/
 | 
| sl@0 |   1197 | TReal TLawUtility::SNRatioL(TUint8* aDecodedData, TUint8* aSrcData, TInt aNoSamples )
 | 
| sl@0 |   1198 | 	{
 | 
| sl@0 |   1199 | 	const TReal KThreshold = 0.0001;
 | 
| sl@0 |   1200 |     TReal ratio = 0.0;
 | 
| sl@0 |   1201 |     //[precondition aDecodedData != NULL ]
 | 
| sl@0 |   1202 |     if( !aDecodedData )
 | 
| sl@0 |   1203 | 		User::Leave( KErrArgument );
 | 
| sl@0 |   1204 | 	//[ precondition aSrcData != NULL ]
 | 
| sl@0 |   1205 | 	if( !aSrcData )
 | 
| sl@0 |   1206 | 		User::Leave( KErrArgument );
 | 
| sl@0 |   1207 |     
 | 
| sl@0 |   1208 | 	TReal   sumSig      = 0.0;    // numerator
 | 
| sl@0 |   1209 | 	TReal   sumNoise    = 0.0; // denominator
 | 
| sl@0 |   1210 | 	TInt    difference  = 0;
 | 
| sl@0 |   1211 | 	TInt16  dataValue   = 0;
 | 
| sl@0 |   1212 | 	TInt    decodeVal   = 0;
 | 
| sl@0 |   1213 | 	for( TInt count = 0; count < aNoSamples; count++ )
 | 
| sl@0 |   1214 | 		{
 | 
| sl@0 |   1215 |         decodeVal = AssembleValL(aDecodedData);
 | 
| sl@0 |   1216 |         dataValue = AssembleValL(aSrcData);
 | 
| sl@0 |   1217 | 		difference = decodeVal - dataValue;
 | 
| sl@0 |   1218 | 		sumSig += (decodeVal*decodeVal);     // sum of the squares of the signal
 | 
| sl@0 |   1219 | 		sumNoise += (difference * difference );  // sum of the square of the difference
 | 
| sl@0 |   1220 | 		aDecodedData+=2;
 | 
| sl@0 |   1221 | 		aSrcData+=2;
 | 
| sl@0 |   1222 | 		}
 | 
| sl@0 |   1223 | 
 | 
| sl@0 |   1224 | 	//[ guard against division by zero ]
 | 
| sl@0 |   1225 | 	if( !( sumNoise >= KThreshold ))
 | 
| sl@0 |   1226 | 		User::Leave( KErrUnderflow );
 | 
| sl@0 |   1227 | 
 | 
| sl@0 |   1228 | 	//[ calculate the sn ratio ]
 | 
| sl@0 |   1229 | 	//[ 10log10( sumSig/SumNoise ]
 | 
| sl@0 |   1230 | 	Math::Log( ratio, (sumSig/sumNoise) );
 | 
| sl@0 |   1231 |     ratio *= 10;  // ratio = 10*log( x**2/(error**2)) in db
 | 
| sl@0 |   1232 |     return ratio;
 | 
| sl@0 |   1233 | 	}
 | 
| sl@0 |   1234 | 
 | 
| sl@0 |   1235 | /**
 | 
| sl@0 |   1236 | *
 | 
| sl@0 |   1237 | * CompareSNRatiosL
 | 
| sl@0 |   1238 | * @param aCodecSN   codec under test SN ratio in db
 | 
| sl@0 |   1239 | * @param aCodecSN2  refernce codec SN ratio in db
 | 
| sl@0 |   1240 | * @param aThreshold difference allowed in db
 | 
| sl@0 |   1241 | * @result within tolerance
 | 
| sl@0 |   1242 | *
 | 
| sl@0 |   1243 | **/
 | 
| sl@0 |   1244 | TBool TLawUtility::CompareSNRatiosL( TReal aCodecSN, TReal aCodecSN2, TReal aTolerance )
 | 
| sl@0 |   1245 | 	{
 | 
| sl@0 |   1246 |     TBool result = ETrue; 
 | 
| sl@0 |   1247 | 	TReal difference = (aCodecSN - aCodecSN2);
 | 
| sl@0 |   1248 | 	//[ it would be nice to replace this with a abs function ?]
 | 
| sl@0 |   1249 | 	if( difference < 0.0 )
 | 
| sl@0 |   1250 | 		{
 | 
| sl@0 |   1251 |          if( aTolerance > difference )
 | 
| sl@0 |   1252 | 			 {
 | 
| sl@0 |   1253 | 			 result = EFalse;
 | 
| sl@0 |   1254 | 			 }
 | 
| sl@0 |   1255 | 		}
 | 
| sl@0 |   1256 | 	else
 | 
| sl@0 |   1257 | 		{
 | 
| sl@0 |   1258 |          if( aTolerance < difference )
 | 
| sl@0 |   1259 | 			 {
 | 
| sl@0 |   1260 | 			 result = EFalse;
 | 
| sl@0 |   1261 | 			 }
 | 
| sl@0 |   1262 | 		}
 | 
| sl@0 |   1263 | 
 | 
| sl@0 |   1264 | 	return result;
 | 
| sl@0 |   1265 | 	}
 | 
| sl@0 |   1266 | 
 | 
| sl@0 |   1267 | /**
 | 
| sl@0 |   1268 | *
 | 
| sl@0 |   1269 | * ComputeSNL compute the Signal to Noise Ratio
 | 
| sl@0 |   1270 | *
 | 
| sl@0 |   1271 | **/
 | 
| sl@0 |   1272 | TReal TLawUtility::ComputeSNL( TReal aSumSigSquared, TReal aSumErrorSquared )
 | 
| sl@0 |   1273 | 	{
 | 
| sl@0 |   1274 | 	 TReal sn = 0.0;
 | 
| sl@0 |   1275 |      const TReal tolerance = 0.001;
 | 
| sl@0 |   1276 | 	 //[precondition error is >= tolerance ]
 | 
| sl@0 |   1277 | 	 if( aSumErrorSquared < tolerance )
 | 
| sl@0 |   1278 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1279 |      //[claculate ratio safely ]
 | 
| sl@0 |   1280 | 	 Math::Log( sn, (aSumSigSquared/aSumErrorSquared));
 | 
| sl@0 |   1281 | 	 sn*= 10;
 | 
| sl@0 |   1282 | 	 return sn;
 | 
| sl@0 |   1283 | 	}
 | 
| sl@0 |   1284 | 
 | 
| sl@0 |   1285 | /**
 | 
| sl@0 |   1286 | *
 | 
| sl@0 |   1287 | * SumSquaredL
 | 
| sl@0 |   1288 | *
 | 
| sl@0 |   1289 | **/
 | 
| sl@0 |   1290 | TReal TLawUtility::SumSquaredL( TUint8* aData, TInt aNoSamples )
 | 
| sl@0 |   1291 | 	{
 | 
| sl@0 |   1292 | 	//[precondition arg is ok ]
 | 
| sl@0 |   1293 |      if( !aData )
 | 
| sl@0 |   1294 | 		 {
 | 
| sl@0 |   1295 | 		 User::Leave(KErrArgument);
 | 
| sl@0 |   1296 | 		 }
 | 
| sl@0 |   1297 | 
 | 
| sl@0 |   1298 | 	 TUint8* pData = aData;
 | 
| sl@0 |   1299 | 	 TInt16 sample ;
 | 
| sl@0 |   1300 | 	 TReal sumSigSquared = 0.0;
 | 
| sl@0 |   1301 | 	 for( TInt count = 0; count < aNoSamples; count++ )
 | 
| sl@0 |   1302 | 		 {
 | 
| sl@0 |   1303 | 		 sample  = static_cast<TInt16>( pData[0] &KAndMask8bit);  
 | 
| sl@0 |   1304 | 		 sample |=  static_cast<TInt16>((pData[1] << 8 ));
 | 
| sl@0 |   1305 | 		 sumSigSquared += (sample*sample);
 | 
| sl@0 |   1306 | 		 pData+=2;
 | 
| sl@0 |   1307 | 		 }
 | 
| sl@0 |   1308 | 
 | 
| sl@0 |   1309 | 	 return sumSigSquared;
 | 
| sl@0 |   1310 | 	}
 | 
| sl@0 |   1311 | 
 | 
| sl@0 |   1312 | /**
 | 
| sl@0 |   1313 | *
 | 
| sl@0 |   1314 | * SumErrorSquaredL
 | 
| sl@0 |   1315 | * @param aData
 | 
| sl@0 |   1316 | * @param aData2
 | 
| sl@0 |   1317 | * @param aNoSamples
 | 
| sl@0 |   1318 | * @result TReal
 | 
| sl@0 |   1319 | *
 | 
| sl@0 |   1320 | **/
 | 
| sl@0 |   1321 | TReal TLawUtility::SumErrorSquaredL( TUint8* aData, TUint8* aData2, TInt aNoSamples )
 | 
| sl@0 |   1322 | 	{
 | 
| sl@0 |   1323 | 	//[precondition aData is not NULL]
 | 
| sl@0 |   1324 | 	 if( !aData )
 | 
| sl@0 |   1325 | 		 {
 | 
| sl@0 |   1326 | 		 User::Leave(KErrArgument);
 | 
| sl@0 |   1327 | 		 }
 | 
| sl@0 |   1328 | 
 | 
| sl@0 |   1329 | 	 //[precondition aData2 is not NULL ]
 | 
| sl@0 |   1330 | 	if( !aData2 )
 | 
| sl@0 |   1331 | 		 {
 | 
| sl@0 |   1332 | 		 User::Leave(KErrArgument);
 | 
| sl@0 |   1333 | 		 }
 | 
| sl@0 |   1334 | 
 | 
| sl@0 |   1335 | 	 TUint8* pData = aData;
 | 
| sl@0 |   1336 | 	 TUint8* pData2 = aData2;
 | 
| sl@0 |   1337 | 	 TInt16 sample ;
 | 
| sl@0 |   1338 | 	 TInt16 sample2;
 | 
| sl@0 |   1339 | 	 TReal sumErrorSquared = 0.0;
 | 
| sl@0 |   1340 | 	 TInt error;
 | 
| sl@0 |   1341 | 	 for( TInt count = 0; count < aNoSamples; count++ )
 | 
| sl@0 |   1342 | 		 {
 | 
| sl@0 |   1343 | 		 error = 0;
 | 
| sl@0 |   1344 | 		 sample  = static_cast<TInt16>( pData[0] &KAndMask8bit);  
 | 
| sl@0 |   1345 | 		 sample |=  static_cast<TInt16>((pData[1] << 8 ));
 | 
| sl@0 |   1346 | 		 sample2  = static_cast<TInt16>( pData2[0] &KAndMask8bit);  
 | 
| sl@0 |   1347 | 		 sample2 |=  static_cast<TInt16>((pData2[1] << 8 ));
 | 
| sl@0 |   1348 | 		 error = sample -sample2; // compute the error
 | 
| sl@0 |   1349 | 		 sumErrorSquared += (error*error); // add error squared to the sum
 | 
| sl@0 |   1350 | 		 pData  +=2;
 | 
| sl@0 |   1351 | 		 pData2 +=2;
 | 
| sl@0 |   1352 | 		 }
 | 
| sl@0 |   1353 | 
 | 
| sl@0 |   1354 | 	 return sumErrorSquared;
 | 
| sl@0 |   1355 | 	}
 | 
| sl@0 |   1356 | 
 | 
| sl@0 |   1357 | /**
 | 
| sl@0 |   1358 | *
 | 
| sl@0 |   1359 | * CTestMuLawCodec_U_0006
 | 
| sl@0 |   1360 | *
 | 
| sl@0 |   1361 | **/
 | 
| sl@0 |   1362 | CTestMuLawCodec_U_0006::CTestMuLawCodec_U_0006()
 | 
| sl@0 |   1363 | 	{
 | 
| sl@0 |   1364 |      //[ set test name]
 | 
| sl@0 |   1365 | 	iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0006-HP");
 | 
| sl@0 |   1366 | 	}
 | 
| sl@0 |   1367 | 
 | 
| sl@0 |   1368 | /**
 | 
| sl@0 |   1369 | *
 | 
| sl@0 |   1370 | * LinearToMuLawSample
 | 
| sl@0 |   1371 | * @param aSample a 16 bit pcm sample
 | 
| sl@0 |   1372 | * @result Mu Law encoded sample
 | 
| sl@0 |   1373 | *
 | 
| sl@0 |   1374 | **/
 | 
| sl@0 |   1375 | TUint8 CTestMuLawCodec_U_0006::LinearToMuLawSample( TInt16 aSample)
 | 
| sl@0 |   1376 | 	{
 | 
| sl@0 |   1377 | 	const int KBias = 0x84;
 | 
| sl@0 |   1378 | 	const int KClip = 32635;
 | 
| sl@0 |   1379 | 	TInt sign = (aSample >> 8) & 0x80;
 | 
| sl@0 |   1380 | 	if(sign)
 | 
| sl@0 |   1381 | 		aSample = static_cast<TInt16>(-aSample);
 | 
| sl@0 |   1382 | 	if(aSample > KClip)
 | 
| sl@0 |   1383 | 		aSample = KClip;
 | 
| sl@0 |   1384 | 	aSample = static_cast<TInt16>(aSample + KBias);
 | 
| sl@0 |   1385 | 	TInt exponent = static_cast<TInt>( MuLawCompressTable[(aSample>>7) & 0xFF]);
 | 
| sl@0 |   1386 | 	TInt mantissa = (aSample >> (exponent+3)) & 0x0F;
 | 
| sl@0 |   1387 | 	TInt compressedByte = ~(sign | (exponent << 4) | mantissa);
 | 
| sl@0 |   1388 | 	return static_cast<TUint8>( compressedByte );
 | 
| sl@0 |   1389 | 	}
 | 
| sl@0 |   1390 | 
 | 
| sl@0 |   1391 | /**
 | 
| sl@0 |   1392 | *
 | 
| sl@0 |   1393 | * ConvertPcmMuLaw
 | 
| sl@0 |   1394 | *
 | 
| sl@0 |   1395 | **/
 | 
| sl@0 |   1396 | void CTestMuLawCodec_U_0006::ConvertPcmMuLawL(TUint8* aSrcData, TUint8* aCodedData, TInt aNumSamples ) 
 | 
| sl@0 |   1397 | 	{
 | 
| sl@0 |   1398 | 	//[ precondition aSrcData ]
 | 
| sl@0 |   1399 |      if( !aSrcData )
 | 
| sl@0 |   1400 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1401 | 	 //[precondition aCodedData ]
 | 
| sl@0 |   1402 | 	 if( !aCodedData )
 | 
| sl@0 |   1403 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1404 | 
 | 
| sl@0 |   1405 | 	 TUint8* pCoded = aCodedData;
 | 
| sl@0 |   1406 | 	 TUint8* pData  = aSrcData ;
 | 
| sl@0 |   1407 | 	 TInt16 pcmSample;
 | 
| sl@0 |   1408 | 	 for( TInt count = 0; count < aNumSamples; count++ )
 | 
| sl@0 |   1409 | 		 {
 | 
| sl@0 |   1410 |           //[ code the data ]
 | 
| sl@0 |   1411 | 		  pcmSample  = static_cast<TInt16>(pData[0]);
 | 
| sl@0 |   1412 | 		  pcmSample |= static_cast<TInt16>((pData[1] << 8 )); 
 | 
| sl@0 |   1413 |           *pCoded++ = LinearToMuLawSample(pcmSample);
 | 
| sl@0 |   1414 | 		  pData+=2;
 | 
| sl@0 |   1415 | 		 }
 | 
| sl@0 |   1416 | 	}
 | 
| sl@0 |   1417 | 
 | 
| sl@0 |   1418 | /**
 | 
| sl@0 |   1419 | *
 | 
| sl@0 |   1420 | * ConvertMuLawPcm
 | 
| sl@0 |   1421 | * 
 | 
| sl@0 |   1422 | **/
 | 
| sl@0 |   1423 | void CTestMuLawCodec_U_0006::ConvertMuLawPcmL(TUint8* aCoded, TUint8* aDecoded, TInt aNumSamples )
 | 
| sl@0 |   1424 | 	{
 | 
| sl@0 |   1425 | 	//[ precondition aCoded ]
 | 
| sl@0 |   1426 | 	if( !aCoded )
 | 
| sl@0 |   1427 | 		User::Leave( KErrArgument );
 | 
| sl@0 |   1428 | 	//[precondition aDecoded ]
 | 
| sl@0 |   1429 | 	if( !aDecoded )
 | 
| sl@0 |   1430 | 		User::Leave( KErrArgument );
 | 
| sl@0 |   1431 | 	
 | 
| sl@0 |   1432 | 	TInt16  pcmSample;
 | 
| sl@0 |   1433 | 	TUint8* pCoded   = aCoded;
 | 
| sl@0 |   1434 | 	TUint8* pDecoded = aDecoded;
 | 
| sl@0 |   1435 | 	//[ lets convert the data ]
 | 
| sl@0 |   1436 | 	for(TInt count = 0; count < aNumSamples; count++ )
 | 
| sl@0 |   1437 | 		{
 | 
| sl@0 |   1438 | 		pcmSample = MuLawDecompressTable[*pCoded++];
 | 
| sl@0 |   1439 | 		*pDecoded++ = static_cast<TUint8>( pcmSample & 0xFF);
 | 
| sl@0 |   1440 | 		*pDecoded++ = static_cast<TUint8>((pcmSample >> 8 ) & 0xFF);
 | 
| sl@0 |   1441 | 		}
 | 
| sl@0 |   1442 | 	}
 | 
| sl@0 |   1443 | 
 | 
| sl@0 |   1444 | /**
 | 
| sl@0 |   1445 | *
 | 
| sl@0 |   1446 | * DoTestStepL
 | 
| sl@0 |   1447 | *
 | 
| sl@0 |   1448 | **/
 | 
| sl@0 |   1449 | TVerdict CTestMuLawCodec_U_0006::DoTestStepL()
 | 
| sl@0 |   1450 | 	{
 | 
| sl@0 |   1451 | 	TVerdict result = EPass;
 | 
| sl@0 |   1452 | 	const TInt KSrcBufferSize     = 400;    // small buffer size
 | 
| sl@0 |   1453 | 	const TInt KHalfSrcBufferSize = 200;    // small buffer size
 | 
| sl@0 |   1454 | 	const TInt KCodedBufferSize   = 200;    // small buffer size
 | 
| sl@0 |   1455 | 	const TInt KLowerLimit        = -800; //lower limit of test range
 | 
| sl@0 |   1456 | 	const TInt KUpperLimit        = 800;  // upper limit of test range +1
 | 
| sl@0 |   1457 | 	
 | 
| sl@0 |   1458 | 	//[ allocate memory buffers]
 | 
| sl@0 |   1459 | 	TUint8* pSymbianSrcData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1460 | 	CleanupStack::PushL(pSymbianSrcData);
 | 
| sl@0 |   1461 | 	TUint8* pIndependentSrcData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1462 | 	CleanupStack::PushL(pIndependentSrcData);
 | 
| sl@0 |   1463 | 	TUint8* pSymbianCodedData = new(ELeave)TUint8[KCodedBufferSize];
 | 
| sl@0 |   1464 | 	CleanupStack::PushL(pSymbianCodedData);
 | 
| sl@0 |   1465 | 	TUint8* pIndependentCodedData = new(ELeave)TUint8[KCodedBufferSize];
 | 
| sl@0 |   1466 | 	CleanupStack::PushL(pIndependentCodedData);
 | 
| sl@0 |   1467 | 	TUint8* pSymbianDecodedData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1468 | 	CleanupStack::PushL(pSymbianDecodedData);
 | 
| sl@0 |   1469 | 	TUint8* pIndependentDecodedData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1470 | 	CleanupStack::PushL(pIndependentDecodedData);
 | 
| sl@0 |   1471 | 	
 | 
| sl@0 |   1472 |     TMMFAudioMuLawToS16PcmCodec decoder;
 | 
| sl@0 |   1473 | 	TMMFAudioSPcm16ToMuLawCodec encoder;
 | 
| sl@0 |   1474 | 
 | 
| sl@0 |   1475 | 	TLawUtility helper;
 | 
| sl@0 |   1476 | 	TReal symbianCodecSN = 0.0;
 | 
| sl@0 |   1477 | 	TReal independentCodecSN = 0.0;
 | 
| sl@0 |   1478 | 
 | 
| sl@0 |   1479 | 	TReal sumRefSig       = 0.0; // sum of sig squared
 | 
| sl@0 |   1480 | 	TReal sumRefError     = 0.0; // sum of error sig squared
 | 
| sl@0 |   1481 | 	TReal sumSymbianSig   = 0.0; // sum of sig squared
 | 
| sl@0 |   1482 | 	TReal sumSymbianError = 0.0; // sum of error sig squared
 | 
| sl@0 |   1483 | 
 | 
| sl@0 |   1484 | 	//[ interate over a suitable range and process each buffer]
 | 
| sl@0 |   1485 | 	for( TInt index = KLowerLimit; index < KUpperLimit; index+= KHalfSrcBufferSize )
 | 
| sl@0 |   1486 | 		{
 | 
| sl@0 |   1487 | 		TInt16 offset = static_cast<TInt16>( index);
 | 
| sl@0 |   1488 | 		//[ fill the src buffers ]
 | 
| sl@0 |   1489 | 		helper.FillSrcBufferL( pSymbianSrcData, KHalfSrcBufferSize, offset );
 | 
| sl@0 |   1490 | 		helper.FillSrcBufferL( pIndependentSrcData, KHalfSrcBufferSize, offset );
 | 
| sl@0 |   1491 | 
 | 
| sl@0 |   1492 | 		//[encode the src data ]
 | 
| sl@0 |   1493 | 		encoder.Convert( pSymbianSrcData, pSymbianCodedData, KHalfSrcBufferSize );
 | 
| sl@0 |   1494 | 		ConvertPcmMuLawL(pIndependentSrcData,pIndependentCodedData,KHalfSrcBufferSize );
 | 
| sl@0 |   1495 | 	
 | 
| sl@0 |   1496 | 		//[ decode the data ]
 | 
| sl@0 |   1497 |         decoder.Convert( pSymbianCodedData, pSymbianDecodedData, KHalfSrcBufferSize );		
 | 
| sl@0 |   1498 | 	    ConvertMuLawPcmL( pIndependentCodedData,pIndependentDecodedData,KHalfSrcBufferSize);		
 | 
| sl@0 |   1499 | 	
 | 
| sl@0 |   1500 | 		//[ check both codecs code the data similarly]
 | 
| sl@0 |   1501 | 		TInt errorCode =helper.CompareCodedDataL(pIndependentCodedData, pSymbianCodedData, KHalfSrcBufferSize );		
 | 
| sl@0 |   1502 | 		if( errorCode != KErrNone )
 | 
| sl@0 |   1503 | 			{
 | 
| sl@0 |   1504 | 			INFO_PRINTF1(_L("Forward Transformation for Mu-Law codec is not conformant to ref codec"));
 | 
| sl@0 |   1505 | 			User::LeaveIfError(errorCode);
 | 
| sl@0 |   1506 | 			}
 | 
| sl@0 |   1507 | 			//[ upate running total sums to be used for signal to noise
 | 
| sl@0 |   1508 | 		// ratio calculations ]
 | 
| sl@0 |   1509 | 		sumRefSig        += helper.SumSquaredL(pIndependentSrcData, KHalfSrcBufferSize);     
 | 
| sl@0 |   1510 | 		sumRefError      += helper.SumErrorSquaredL(pIndependentSrcData,pIndependentDecodedData,KHalfSrcBufferSize); 
 | 
| sl@0 |   1511 | 		sumSymbianSig    += helper.SumSquaredL(pSymbianSrcData,KHalfSrcBufferSize);
 | 
| sl@0 |   1512 | 		sumSymbianError  += helper.SumErrorSquaredL(pSymbianSrcData,pSymbianDecodedData,KHalfSrcBufferSize);
 | 
| sl@0 |   1513 | 		}
 | 
| sl@0 |   1514 |  		
 | 
| sl@0 |   1515 | 	const TReal KTolerance = 1; // allow for a 1 db tolerance
 | 
| sl@0 |   1516 | 	symbianCodecSN     = helper.ComputeSNL(sumSymbianSig,sumSymbianError);
 | 
| sl@0 |   1517 | 	independentCodecSN = helper.ComputeSNL(sumRefSig, sumRefError);
 | 
| sl@0 |   1518 |     // Gamma = (dynamic range of codec /signal std deviation )
 | 
| sl@0 |   1519 | 	INFO_PRINTF1(_L("We would expect S/N ration to be greater than 35db for an MuLaw codec with Gamma = 10"));
 | 
| sl@0 |   1520 | 	INFO_PRINTF2(_L("Signal/Noise Ratio Symbian Codec %f"), symbianCodecSN ); 
 | 
| sl@0 |   1521 | 	INFO_PRINTF2(_L("Signal/Noise Ratio Reference Codec %f"), independentCodecSN ); 
 | 
| sl@0 |   1522 | 
 | 
| sl@0 |   1523 | 	//[ compare the s/n ratio's of the two codec implementations]
 | 
| sl@0 |   1524 | 	if( !helper.CompareSNRatiosL( symbianCodecSN, independentCodecSN, KTolerance ))
 | 
| sl@0 |   1525 | 		{
 | 
| sl@0 |   1526 | 		//[ fail the test because the s/n ratios were divergent ]
 | 
| sl@0 |   1527 | 		result = EFail;
 | 
| sl@0 |   1528 | 		}
 | 
| sl@0 |   1529 | 	CleanupStack::PopAndDestroy(6,pSymbianSrcData); //pSymbianSrcData,pIndependentSrcData,
 | 
| sl@0 |   1530 | 	                                                //pSymbianCodedData,pIndependentCodedData
 | 
| sl@0 |   1531 | 	                                                //pSymbianDecodedData,pIndependentDecodedData 
 | 
| sl@0 |   1532 | 	
 | 
| sl@0 |   1533 | 	return result;
 | 
| sl@0 |   1534 | 	}
 | 
| sl@0 |   1535 | 
 | 
| sl@0 |   1536 | /**
 | 
| sl@0 |   1537 | *
 | 
| sl@0 |   1538 | *  DoTestStepPreambleL
 | 
| sl@0 |   1539 | *
 | 
| sl@0 |   1540 | **/
 | 
| sl@0 |   1541 | TVerdict CTestMuLawCodec_U_0006::DoTestStepPreambleL(void)
 | 
| sl@0 |   1542 | 	{
 | 
| sl@0 |   1543 | 	TVerdict result = EPass;
 | 
| sl@0 |   1544 | 	return result; //nothing doing
 | 
| sl@0 |   1545 | 	}
 | 
| sl@0 |   1546 | 
 | 
| sl@0 |   1547 | /**
 | 
| sl@0 |   1548 | *
 | 
| sl@0 |   1549 | * DoTestStepPostambleL
 | 
| sl@0 |   1550 | *
 | 
| sl@0 |   1551 | **/
 | 
| sl@0 |   1552 | TVerdict CTestMuLawCodec_U_0006::DoTestStepPostambleL(void)
 | 
| sl@0 |   1553 | 	{
 | 
| sl@0 |   1554 | 	TVerdict result = EPass;
 | 
| sl@0 |   1555 | 	return result; //nothing doing
 | 
| sl@0 |   1556 | 	}
 | 
| sl@0 |   1557 | 
 | 
| sl@0 |   1558 | /**
 | 
| sl@0 |   1559 | *
 | 
| sl@0 |   1560 | * Mu-Law Compression Table
 | 
| sl@0 |   1561 | *
 | 
| sl@0 |   1562 | **/
 | 
| sl@0 |   1563 | const TInt8 CTestMuLawCodec_U_0006::MuLawCompressTable[PcmToMuLawCompressionTableSize] =
 | 
| sl@0 |   1564 | {
 | 
| sl@0 |   1565 | 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
 | 
| sl@0 |   1566 | 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
 | 
| sl@0 |   1567 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
 | 
| sl@0 |   1568 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
 | 
| sl@0 |   1569 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1570 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1571 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1572 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1573 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1574 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1575 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1576 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1577 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1578 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1579 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1580 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
 | 
| sl@0 |   1581 | };
 | 
| sl@0 |   1582 | 
 | 
| sl@0 |   1583 | /**
 | 
| sl@0 |   1584 | *
 | 
| sl@0 |   1585 | * Mu-Law Decompression Table
 | 
| sl@0 |   1586 | *
 | 
| sl@0 |   1587 | **/
 | 
| sl@0 |   1588 | const TInt16 CTestMuLawCodec_U_0006::MuLawDecompressTable[MuLawToPcmCompressionTableSize]=
 | 
| sl@0 |   1589 | {
 | 
| sl@0 |   1590 | -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
 | 
| sl@0 |   1591 | -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
 | 
| sl@0 |   1592 | -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
 | 
| sl@0 |   1593 | -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
 | 
| sl@0 |   1594 | -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
 | 
| sl@0 |   1595 | -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
 | 
| sl@0 |   1596 | -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
 | 
| sl@0 |   1597 | -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
 | 
| sl@0 |   1598 | -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
 | 
| sl@0 |   1599 | -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
 | 
| sl@0 |   1600 | -876, -844, -812, -780, -748, -716, -684, -652,
 | 
| sl@0 |   1601 | -620, -588, -556, -524, -492, -460, -428, -396,
 | 
| sl@0 |   1602 | -372, -356, -340, -324, -308, -292, -276, -260,
 | 
| sl@0 |   1603 | -244, -228, -212, -196, -180, -164, -148, -132,
 | 
| sl@0 |   1604 | -120, -112, -104, -96, -88, -80, -72, -64,
 | 
| sl@0 |   1605 | -56, -48, -40, -32, -24, -16, -8, 0,
 | 
| sl@0 |   1606 | 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
 | 
| sl@0 |   1607 | 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
 | 
| sl@0 |   1608 | 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
 | 
| sl@0 |   1609 | 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
 | 
| sl@0 |   1610 | 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
 | 
| sl@0 |   1611 | 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
 | 
| sl@0 |   1612 | 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
 | 
| sl@0 |   1613 | 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
 | 
| sl@0 |   1614 | 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
 | 
| sl@0 |   1615 | 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
 | 
| sl@0 |   1616 | 876, 844, 812, 780, 748, 716, 684, 652,
 | 
| sl@0 |   1617 | 620, 588, 556, 524, 492, 460, 428, 396,
 | 
| sl@0 |   1618 | 372, 356, 340, 324, 308, 292, 276, 260,
 | 
| sl@0 |   1619 | 244, 228, 212, 196, 180, 164, 148, 132,
 | 
| sl@0 |   1620 | 120, 112, 104, 96, 88, 80, 72, 64,
 | 
| sl@0 |   1621 | 56, 48, 40, 32, 24, 16, 8, 0
 | 
| sl@0 |   1622 | };
 | 
| sl@0 |   1623 | 
 | 
| sl@0 |   1624 | /**
 | 
| sl@0 |   1625 | *
 | 
| sl@0 |   1626 | * CTestALawCodec_U_0004
 | 
| sl@0 |   1627 | *
 | 
| sl@0 |   1628 | **/
 | 
| sl@0 |   1629 | CTestALawCodec_U_0004::CTestALawCodec_U_0004()
 | 
| sl@0 |   1630 | 	{
 | 
| sl@0 |   1631 |     //[ set test name ]
 | 
| sl@0 |   1632 | 	iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0004-HP");
 | 
| sl@0 |   1633 | 	}
 | 
| sl@0 |   1634 | 
 | 
| sl@0 |   1635 | /**
 | 
| sl@0 |   1636 | *
 | 
| sl@0 |   1637 | * ConvertPcmALaw converts Pcm 16 to 8bit ALaw
 | 
| sl@0 |   1638 | * @param aSrcData The src data
 | 
| sl@0 |   1639 | * @param aCoded   The coded result
 | 
| sl@0 |   1640 | * @param aNumSamples The number of samples to be processed
 | 
| sl@0 |   1641 | * @precondition aSrcData is not NULL
 | 
| sl@0 |   1642 | * @precondition aCodedData is not NULL
 | 
| sl@0 |   1643 | * @precondition there is sufficient room in the destination
 | 
| sl@0 |   1644 | * to contain the coded samples
 | 
| sl@0 |   1645 | *
 | 
| sl@0 |   1646 | **/
 | 
| sl@0 |   1647 | void CTestALawCodec_U_0004::ConvertPcmALawL(TUint8* aSrcData, TUint8* aCodedData, TInt aNumSamples )
 | 
| sl@0 |   1648 | 	{
 | 
| sl@0 |   1649 | 	//[ precondition aSrcData ]
 | 
| sl@0 |   1650 |      if( !aSrcData )
 | 
| sl@0 |   1651 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1652 | 	 //[precondition aCodedData ]
 | 
| sl@0 |   1653 | 	 if( !aCodedData )
 | 
| sl@0 |   1654 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1655 | 
 | 
| sl@0 |   1656 | 	 TUint8* pCoded = aCodedData;
 | 
| sl@0 |   1657 | 	 TUint8* pData  = aSrcData ;
 | 
| sl@0 |   1658 | 	 TInt16 pcmSample;
 | 
| sl@0 |   1659 | 	 for( TInt count = 0; count < aNumSamples; count++ )
 | 
| sl@0 |   1660 | 		 {
 | 
| sl@0 |   1661 |           //[ code the data ]
 | 
| sl@0 |   1662 | 		  pcmSample  = static_cast<TInt16>(pData[0]);
 | 
| sl@0 |   1663 | 		  pcmSample |= static_cast<TInt16>((pData[1] << 8 )); 
 | 
| sl@0 |   1664 |           *pCoded++ = LinearToALawSample(pcmSample);
 | 
| sl@0 |   1665 | 		  pData+=2;
 | 
| sl@0 |   1666 | 		 }
 | 
| sl@0 |   1667 | 	}
 | 
| sl@0 |   1668 | 
 | 
| sl@0 |   1669 | /**
 | 
| sl@0 |   1670 | *
 | 
| sl@0 |   1671 | * ConvertALawPcm converts from 8bit ALaw to Pcm16
 | 
| sl@0 |   1672 | * @param aCoded The coded data
 | 
| sl@0 |   1673 | * @param aDecoded The decoded result
 | 
| sl@0 |   1674 | * @param aNumSamples The number of samples to be processed
 | 
| sl@0 |   1675 | * @precondition aCoded is not NULL
 | 
| sl@0 |   1676 | * @precondition aDecoded is not NULL
 | 
| sl@0 |   1677 | * @precondition there is sufficient room in the destination
 | 
| sl@0 |   1678 | * to contain the coded samples
 | 
| sl@0 |   1679 | *
 | 
| sl@0 |   1680 | **/
 | 
| sl@0 |   1681 | void CTestALawCodec_U_0004::ConvertALawPcmL(TUint8* aCoded, TUint8* aDecoded, TInt aNumSamples )
 | 
| sl@0 |   1682 | 	{
 | 
| sl@0 |   1683 | 	 //[ precondition aSrcData ]
 | 
| sl@0 |   1684 |      if( !aCoded )
 | 
| sl@0 |   1685 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1686 | 	 //[precondition aCodedData ]
 | 
| sl@0 |   1687 | 	 if( !aDecoded )
 | 
| sl@0 |   1688 | 		 User::Leave( KErrArgument );
 | 
| sl@0 |   1689 |    
 | 
| sl@0 |   1690 | 	 TInt16  pcmSample;
 | 
| sl@0 |   1691 |      TUint8* pCoded   = aCoded;
 | 
| sl@0 |   1692 | 	 TUint8* pDecoded = aDecoded;
 | 
| sl@0 |   1693 | 	 //[ lets convert the data ]
 | 
| sl@0 |   1694 |      for(TInt count = 0; count < aNumSamples; count++ )
 | 
| sl@0 |   1695 | 		 {
 | 
| sl@0 |   1696 |           pcmSample = ALawDecompressTable[*pCoded++];
 | 
| sl@0 |   1697 |           *pDecoded++ = static_cast<TUint8>(pcmSample & 0xFF);
 | 
| sl@0 |   1698 | 		  *pDecoded++ = static_cast<TUint8>((pcmSample >> 8 ) & 0xFF);
 | 
| sl@0 |   1699 | 		 }
 | 
| sl@0 |   1700 | 	}
 | 
| sl@0 |   1701 | 
 | 
| sl@0 |   1702 | /**
 | 
| sl@0 |   1703 | *
 | 
| sl@0 |   1704 | * LinearToALawSample converts a Pcm16 sample to ALaw
 | 
| sl@0 |   1705 | * @param aSample the PCM 16 sample to be converted
 | 
| sl@0 |   1706 | * @result coded result
 | 
| sl@0 |   1707 | * 
 | 
| sl@0 |   1708 | **/
 | 
| sl@0 |   1709 | TUint8 CTestALawCodec_U_0004::LinearToALawSample(TInt16 aSample)
 | 
| sl@0 |   1710 | 	{
 | 
| sl@0 |   1711 | 	const TInt KClip = 32635;
 | 
| sl@0 |   1712 | 	TInt sign;
 | 
| sl@0 |   1713 | 	TInt exponent;
 | 
| sl@0 |   1714 | 	TInt mantissa;
 | 
| sl@0 |   1715 | 	TUint8 compressedByte;
 | 
| sl@0 |   1716 | 	sign = ((~aSample) >> 8) & 0x80;
 | 
| sl@0 |   1717 | 	if(!sign)
 | 
| sl@0 |   1718 | 		aSample = static_cast<TInt16>(-aSample);
 | 
| sl@0 |   1719 | 	if(aSample > KClip)
 | 
| sl@0 |   1720 | 		aSample = KClip;
 | 
| sl@0 |   1721 | 	if(aSample >= 256)
 | 
| sl@0 |   1722 | 		{
 | 
| sl@0 |   1723 | 		exponent = static_cast<TInt>( ALawCompressTable[(aSample >> 8) & 0x7F]);
 | 
| sl@0 |   1724 | 		mantissa = (aSample >> (exponent + 3) ) & 0x0F;
 | 
| sl@0 |   1725 | 		compressedByte = static_cast<TUint8> ((exponent << 4) | mantissa);
 | 
| sl@0 |   1726 | 		}
 | 
| sl@0 |   1727 | 	else
 | 
| sl@0 |   1728 | 		{
 | 
| sl@0 |   1729 | 		compressedByte = static_cast<TUint8> (aSample >> 4);
 | 
| sl@0 |   1730 | 		}
 | 
| sl@0 |   1731 | 	compressedByte ^= (sign ^ 0x55);
 | 
| sl@0 |   1732 | 	return compressedByte;
 | 
| sl@0 |   1733 | 	}
 | 
| sl@0 |   1734 | 
 | 
| sl@0 |   1735 | /**
 | 
| sl@0 |   1736 | *
 | 
| sl@0 |   1737 | * DoTestStepL
 | 
| sl@0 |   1738 | * 
 | 
| sl@0 |   1739 | **/
 | 
| sl@0 |   1740 | TVerdict CTestALawCodec_U_0004::DoTestStepL()
 | 
| sl@0 |   1741 | 	{
 | 
| sl@0 |   1742 | 	TVerdict result = EPass;
 | 
| sl@0 |   1743 | 	const TInt KSrcBufferSize     = 400;    // small buffer size
 | 
| sl@0 |   1744 | 	const TInt KHalfSrcBufferSize = 200;    // small buffer size
 | 
| sl@0 |   1745 | 	const TInt KCodedBufferSize   = 200;    // small buffer size
 | 
| sl@0 |   1746 | 	const TInt KLowerLimit        = -400; //lower limit of test range
 | 
| sl@0 |   1747 | 	const TInt KUpperLimit        = 400;  // upper limit of test range +1
 | 
| sl@0 |   1748 | 	
 | 
| sl@0 |   1749 | 	//[ allocate memory buffers]
 | 
| sl@0 |   1750 | 	TUint8* pSymbianSrcData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1751 | 	CleanupStack::PushL(pSymbianSrcData);
 | 
| sl@0 |   1752 | 	TUint8* pIndependentSrcData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1753 | 	CleanupStack::PushL(pIndependentSrcData);
 | 
| sl@0 |   1754 | 	TUint8* pSymbianCodedData = new(ELeave)TUint8[KCodedBufferSize];
 | 
| sl@0 |   1755 | 	CleanupStack::PushL(pSymbianCodedData);
 | 
| sl@0 |   1756 | 	TUint8* pIndependentCodedData = new(ELeave)TUint8[KCodedBufferSize];
 | 
| sl@0 |   1757 | 	CleanupStack::PushL(pIndependentCodedData);
 | 
| sl@0 |   1758 | 	TUint8* pSymbianDecodedData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1759 | 	CleanupStack::PushL(pSymbianDecodedData);
 | 
| sl@0 |   1760 | 	TUint8* pIndependentDecodedData = new(ELeave)TUint8[KSrcBufferSize];
 | 
| sl@0 |   1761 | 	CleanupStack::PushL(pIndependentDecodedData);
 | 
| sl@0 |   1762 | 	
 | 
| sl@0 |   1763 | 	TMMFAudioSPcm16ToAlawCodec encoder;
 | 
| sl@0 |   1764 | 	TMMFAudioALawToS16PcmCodec decoder;
 | 
| sl@0 |   1765 |     
 | 
| sl@0 |   1766 | 	TLawUtility helper;
 | 
| sl@0 |   1767 | 	TReal symbianCodecSN = 0.0;
 | 
| sl@0 |   1768 | 	TReal independentCodecSN = 0.0;
 | 
| sl@0 |   1769 | 
 | 
| sl@0 |   1770 | 	TReal sumRefSig       = 0.0; // sum of sig squared
 | 
| sl@0 |   1771 | 	TReal sumRefError     = 0.0; // sum of error sig squared
 | 
| sl@0 |   1772 | 	TReal sumSymbianSig   = 0.0; // sum of sig squared
 | 
| sl@0 |   1773 | 	TReal sumSymbianError = 0.0; // sum of error sig squared
 | 
| sl@0 |   1774 | 
 | 
| sl@0 |   1775 | 	//[ interate over a suitable range and process each buffer]
 | 
| sl@0 |   1776 | 	for( TInt index = KLowerLimit; index < KUpperLimit; index+= KHalfSrcBufferSize )
 | 
| sl@0 |   1777 | 		{
 | 
| sl@0 |   1778 | 		TInt16 offset = static_cast<TInt16>( index);
 | 
| sl@0 |   1779 | 		//[ fill the src buffers ]
 | 
| sl@0 |   1780 | 		helper.FillSrcBufferL( pSymbianSrcData, KHalfSrcBufferSize, offset );
 | 
| sl@0 |   1781 | 		helper.FillSrcBufferL( pIndependentSrcData, KHalfSrcBufferSize, offset );
 | 
| sl@0 |   1782 | 
 | 
| sl@0 |   1783 | 		//[encode the src data ]
 | 
| sl@0 |   1784 | 		encoder.Convert( pSymbianSrcData, pSymbianCodedData, KHalfSrcBufferSize );
 | 
| sl@0 |   1785 | 		ConvertPcmALawL(pIndependentSrcData,pIndependentCodedData,KHalfSrcBufferSize );
 | 
| sl@0 |   1786 | 	
 | 
| sl@0 |   1787 | 		//[ decode the data ]
 | 
| sl@0 |   1788 |         decoder.Convert( pSymbianCodedData, pSymbianDecodedData, KHalfSrcBufferSize );		
 | 
| sl@0 |   1789 | 	    ConvertALawPcmL( pIndependentCodedData,pIndependentDecodedData,KHalfSrcBufferSize);		
 | 
| sl@0 |   1790 | 	
 | 
| sl@0 |   1791 | 		//[ check both codecs code the data similarly]
 | 
| sl@0 |   1792 | 		 TInt errorCode = helper.CompareCodedDataL(pIndependentCodedData, pSymbianCodedData, KHalfSrcBufferSize );
 | 
| sl@0 |   1793 | 		 if( errorCode != KErrNone )
 | 
| sl@0 |   1794 | 			 {
 | 
| sl@0 |   1795 | 			 INFO_PRINTF1(_L("Forward Transformation for ALaw codec is not conformant to ref codec"));
 | 
| sl@0 |   1796 | 			 User::LeaveIfError(errorCode);
 | 
| sl@0 |   1797 | 			 }
 | 
| sl@0 |   1798 | 	    
 | 
| sl@0 |   1799 | 		//[ upate running total sums to be used for signal to noise
 | 
| sl@0 |   1800 | 		// ratio calculations ]
 | 
| sl@0 |   1801 | 		sumRefSig        += helper.SumSquaredL(pIndependentSrcData, KHalfSrcBufferSize);     
 | 
| sl@0 |   1802 | 		sumRefError      += helper.SumErrorSquaredL(pIndependentSrcData,pIndependentDecodedData,KHalfSrcBufferSize); 
 | 
| sl@0 |   1803 | 		sumSymbianSig    += helper.SumSquaredL(pSymbianSrcData,KHalfSrcBufferSize);
 | 
| sl@0 |   1804 | 		sumSymbianError  += helper.SumErrorSquaredL(pSymbianSrcData,pSymbianDecodedData,KHalfSrcBufferSize);
 | 
| sl@0 |   1805 | 		}
 | 
| sl@0 |   1806 | 	const TReal KTolerance = 1; // allow for a 1 db tolerance
 | 
| sl@0 |   1807 | 	symbianCodecSN     = helper.ComputeSNL(sumSymbianSig,sumSymbianError);
 | 
| sl@0 |   1808 | 	independentCodecSN = helper.ComputeSNL(sumRefSig, sumRefError);
 | 
| sl@0 |   1809 |     // Gamma = (dynamic range of codec /signal std deviation )
 | 
| sl@0 |   1810 | 	INFO_PRINTF1(_L("We would expect S/N ration to be greater than 30db for an ALaw codec with Gamma = 10"));
 | 
| sl@0 |   1811 | 	INFO_PRINTF2(_L("Signal/Noise Ratio Symbian Codec %f"), symbianCodecSN ); 
 | 
| sl@0 |   1812 | 	INFO_PRINTF2(_L("Signal/Noise Ratio Reference Codec %f"), independentCodecSN ); 
 | 
| sl@0 |   1813 | 
 | 
| sl@0 |   1814 | 	//[ compare the s/n ratio's of the two codec implementations]
 | 
| sl@0 |   1815 | 	if( !helper.CompareSNRatiosL( symbianCodecSN, independentCodecSN, KTolerance ))
 | 
| sl@0 |   1816 | 		{
 | 
| sl@0 |   1817 | 		//[ fail the test because the s/n ratios were divergent ]
 | 
| sl@0 |   1818 | 		result = EFail;
 | 
| sl@0 |   1819 | 		}
 | 
| sl@0 |   1820 | 	
 | 
| sl@0 |   1821 | 	CleanupStack::PopAndDestroy(6,pSymbianSrcData); //pSymbianSrcData,pIndependentSrcData,
 | 
| sl@0 |   1822 | 	                                //pSymbianCodedData,pIndependentCodedData
 | 
| sl@0 |   1823 | 	                                //pSymbianDecodedData,pIndependentDecodedData 
 | 
| sl@0 |   1824 | 	return result;                  
 | 
| sl@0 |   1825 | 	}
 | 
| sl@0 |   1826 | 
 | 
| sl@0 |   1827 | /**
 | 
| sl@0 |   1828 | *
 | 
| sl@0 |   1829 | * DoTestStepPreambleL
 | 
| sl@0 |   1830 | *
 | 
| sl@0 |   1831 | **/
 | 
| sl@0 |   1832 | TVerdict CTestALawCodec_U_0004::DoTestStepPreambleL(void)
 | 
| sl@0 |   1833 | 	{
 | 
| sl@0 |   1834 | 	TVerdict result = EPass;
 | 
| sl@0 |   1835 | 	return result; //nothing doing
 | 
| sl@0 |   1836 | 	}
 | 
| sl@0 |   1837 | /**
 | 
| sl@0 |   1838 | *
 | 
| sl@0 |   1839 | * DoTestStepPostambleL
 | 
| sl@0 |   1840 | *
 | 
| sl@0 |   1841 | **/
 | 
| sl@0 |   1842 | TVerdict CTestALawCodec_U_0004::DoTestStepPostambleL(void)
 | 
| sl@0 |   1843 | 	{
 | 
| sl@0 |   1844 | 	TVerdict result = EPass;
 | 
| sl@0 |   1845 | 	return result; //nothing doing
 | 
| sl@0 |   1846 | 	}
 | 
| sl@0 |   1847 | /**
 | 
| sl@0 |   1848 | *
 | 
| sl@0 |   1849 | * ALaw Compression Table
 | 
| sl@0 |   1850 | *
 | 
| sl@0 |   1851 | **/
 | 
| sl@0 |   1852 | const TInt8 CTestALawCodec_U_0004::ALawCompressTable[PcmToALawCompressionTableSize] =
 | 
| sl@0 |   1853 | {
 | 
| sl@0 |   1854 | 1,1,2,2,3,3,3,3,
 | 
| sl@0 |   1855 | 4,4,4,4,4,4,4,4,
 | 
| sl@0 |   1856 | 5,5,5,5,5,5,5,5,
 | 
| sl@0 |   1857 | 5,5,5,5,5,5,5,5,
 | 
| sl@0 |   1858 | 6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1859 | 6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1860 | 6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1861 | 6,6,6,6,6,6,6,6,
 | 
| sl@0 |   1862 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1863 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1864 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1865 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1866 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1867 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1868 | 7,7,7,7,7,7,7,7,
 | 
| sl@0 |   1869 | 7,7,7,7,7,7,7,7
 | 
| sl@0 |   1870 | };
 | 
| sl@0 |   1871 | 
 | 
| sl@0 |   1872 | /**
 | 
| sl@0 |   1873 | *
 | 
| sl@0 |   1874 | * ALaw Decompression Table 
 | 
| sl@0 |   1875 | *
 | 
| sl@0 |   1876 | **/
 | 
| sl@0 |   1877 | const TInt16 CTestALawCodec_U_0004::ALawDecompressTable[ALawToPcmCompressionTableSize] =
 | 
| sl@0 |   1878 | {
 | 
| sl@0 |   1879 | -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
 | 
| sl@0 |   1880 | -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
 | 
| sl@0 |   1881 | -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
 | 
| sl@0 |   1882 | -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
 | 
| sl@0 |   1883 | -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,
 | 
| sl@0 |   1884 | -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,
 | 
| sl@0 |   1885 | -11008,-10496,-12032,-11520,-8960, -8448, -9984, -9472,
 | 
| sl@0 |   1886 | -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,
 | 
| sl@0 |   1887 | -344, -328, -376, -360, -280, -264, -312, -296,
 | 
| sl@0 |   1888 | -472, -456, -504, -488, -408, -392, -440, -424,
 | 
| sl@0 |   1889 | -88, -72, -120, -104, -24, -8, -56, -40,
 | 
| sl@0 |   1890 | -216, -200, -248, -232, -152, -136, -184, -168,
 | 
| sl@0 |   1891 | -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
 | 
| sl@0 |   1892 | -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
 | 
| sl@0 |   1893 | -688, -656, -752, -720, -560, -528, -624, -592,
 | 
| sl@0 |   1894 | -944, -912, -1008, -976, -816, -784, -880, -848,
 | 
| sl@0 |   1895 | 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
 | 
| sl@0 |   1896 | 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
 | 
| sl@0 |   1897 | 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
 | 
| sl@0 |   1898 | 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
 | 
| sl@0 |   1899 | 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
 | 
| sl@0 |   1900 | 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
 | 
| sl@0 |   1901 | 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
 | 
| sl@0 |   1902 | 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
 | 
| sl@0 |   1903 | 344, 328, 376, 360, 280, 264, 312, 296,
 | 
| sl@0 |   1904 | 472, 456, 504, 488, 408, 392, 440, 424,
 | 
| sl@0 |   1905 | 88, 72, 120, 104, 24, 8, 56, 40,
 | 
| sl@0 |   1906 | 216, 200, 248, 232, 152, 136, 184, 168,
 | 
| sl@0 |   1907 | 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
 | 
| sl@0 |   1908 | 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
 | 
| sl@0 |   1909 | 688, 656, 752, 720, 560, 528, 624, 592,
 | 
| sl@0 |   1910 | 944, 912, 1008, 976, 816, 784, 880, 848
 | 
| sl@0 |   1911 | };
 | 
| sl@0 |   1912 | 
 | 
| sl@0 |   1913 | /**
 | 
| sl@0 |   1914 | *
 | 
| sl@0 |   1915 | * CTestIMaadCodec
 | 
| sl@0 |   1916 | *
 | 
| sl@0 |   1917 | **/
 | 
| sl@0 |   1918 | CTestIMaadCodec::CTestIMaadCodec()
 | 
| sl@0 |   1919 | 	{
 | 
| sl@0 |   1920 | 	//[ set test name ]
 | 
| sl@0 |   1921 | 	iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0022-HP");
 | 
| sl@0 |   1922 | 	}
 | 
| sl@0 |   1923 | 
 | 
| sl@0 |   1924 | /**
 | 
| sl@0 |   1925 | *
 | 
| sl@0 |   1926 | * DoTestStepL
 | 
| sl@0 |   1927 | *
 | 
| sl@0 |   1928 | **/
 | 
| sl@0 |   1929 | TVerdict CTestIMaadCodec::DoTestStepL()
 | 
| sl@0 |   1930 | 	{
 | 
| sl@0 |   1931 | 	__MM_HEAP_MARK;    
 | 
| sl@0 |   1932 | 	TVerdict result = EPass;
 | 
| sl@0 |   1933 | 	TInt srcBufferSize;
 | 
| sl@0 |   1934 | 	TInt sinkBufferSize;
 | 
| sl@0 |   1935 | 	const TReal KExpectedSNRatioDb = 30.0; //30 db for now
 | 
| sl@0 |   1936 |    
 | 
| sl@0 |   1937 | 	//[ Create coder and decoder codecs ]
 | 
| sl@0 |   1938 | 	CMMFPcm16ToImaAdpcmHwDevice* pHwDevice = CMMFPcm16ToImaAdpcmHwDevice::NewL();
 | 
| sl@0 |   1939 |     CleanupStack::PushL( pHwDevice );
 | 
| sl@0 |   1940 | 
 | 
| sl@0 |   1941 | 	CMMFSwCodec& theCodec = pHwDevice->Codec();
 | 
| sl@0 |   1942 | 
 | 
| sl@0 |   1943 | 	CMMFImaAdpcmToPcm16CodecHwDevice* pHwDecoder = CMMFImaAdpcmToPcm16CodecHwDevice::NewL();
 | 
| sl@0 |   1944 |     CleanupStack::PushL( pHwDecoder );
 | 
| sl@0 |   1945 | 
 | 
| sl@0 |   1946 | 	CMMFSwCodec& theDecoder = pHwDecoder->Codec();
 | 
| sl@0 |   1947 | 
 | 
| sl@0 |   1948 | 	//[ Create data buffers with position != 0]
 | 
| sl@0 |   1949 | 	srcBufferSize  = 100; // arbitrary non zero size
 | 
| sl@0 |   1950 | 	sinkBufferSize = 100;
 | 
| sl@0 |   1951 |     CMMFDescriptorBuffer* pSrcBuffer =  CMMFDescriptorBuffer::NewL( srcBufferSize ); 
 | 
| sl@0 |   1952 | 	CleanupStack::PushL( pSrcBuffer );
 | 
| sl@0 |   1953 | 	
 | 
| sl@0 |   1954 | 	CMMFDescriptorBuffer* pSinkBuffer = CMMFDescriptorBuffer::NewL( sinkBufferSize ); 
 | 
| sl@0 |   1955 | 	CleanupStack::PushL( pSinkBuffer );
 | 
| sl@0 |   1956 | 
 | 
| sl@0 |   1957 | 	//[ trap & check error code ]
 | 
| sl@0 |   1958 | 	TInt errCode;
 | 
| sl@0 |   1959 | 	pSrcBuffer->Data().SetLength(srcBufferSize);
 | 
| sl@0 |   1960 | 	pSinkBuffer->Data().SetLength(sinkBufferSize);
 | 
| sl@0 |   1961 | 	pSrcBuffer->SetPosition(1);
 | 
| sl@0 |   1962 |     TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
 | 
| sl@0 |   1963 | 	if( errCode != KErrArgument )
 | 
| sl@0 |   1964 | 		{
 | 
| sl@0 |   1965 | 		result = EFail;
 | 
| sl@0 |   1966 | 		return result;
 | 
| sl@0 |   1967 | 		}
 | 
| sl@0 |   1968 | 
 | 
| sl@0 |   1969 |   	//[set position of sink buffer to nonzero value]
 | 
| sl@0 |   1970 | 	pSrcBuffer->SetPosition(0);
 | 
| sl@0 |   1971 |     pSinkBuffer->SetPosition(1);
 | 
| sl@0 |   1972 |     TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
 | 
| sl@0 |   1973 | 	if( errCode != KErrArgument )
 | 
| sl@0 |   1974 | 		{
 | 
| sl@0 |   1975 | 		result = EFail;
 | 
| sl@0 |   1976 | 		return result;
 | 
| sl@0 |   1977 | 		}
 | 
| sl@0 |   1978 | 
 | 
| sl@0 |   1979 | 	//[set position of sink and src to nonzero value ]
 | 
| sl@0 |   1980 | 	pSrcBuffer->SetPosition(1);
 | 
| sl@0 |   1981 |     pSinkBuffer->SetPosition(1);
 | 
| sl@0 |   1982 |     TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
 | 
| sl@0 |   1983 | 	if( errCode != KErrArgument )
 | 
| sl@0 |   1984 | 		{
 | 
| sl@0 |   1985 | 		result = EFail;
 | 
| sl@0 |   1986 | 		return result;
 | 
| sl@0 |   1987 | 		}
 | 
| sl@0 |   1988 | 
 | 
| sl@0 |   1989 | 	//[ reset the position of both buffers to zero ]
 | 
| sl@0 |   1990 |     pSrcBuffer->SetPosition(0);
 | 
| sl@0 |   1991 |     pSinkBuffer->SetPosition(0);
 | 
| sl@0 |   1992 |     //[ set the src/sink buffer sizes to src and sink
 | 
| sl@0 |   1993 | 	// buffer sizes and fill src with data ]
 | 
| sl@0 |   1994 | 	CleanupStack::PopAndDestroy(2, pSrcBuffer); // pSrcBuffer, pSinkBuffer
 | 
| sl@0 |   1995 |     
 | 
| sl@0 |   1996 | 	//[Create Source & Sink and fill source data in ]
 | 
| sl@0 |   1997 | 	srcBufferSize = theCodec.SourceBufferSize();
 | 
| sl@0 |   1998 | 	pSrcBuffer  = CMMFDescriptorBuffer::NewL( srcBufferSize );
 | 
| sl@0 |   1999 | 	CleanupStack::PushL( pSrcBuffer );
 | 
| sl@0 |   2000 | 
 | 
| sl@0 |   2001 | 	CMMFDescriptorBuffer* pDecodedBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
 | 
| sl@0 |   2002 | 	CleanupStack::PushL( pDecodedBuffer );
 | 
| sl@0 |   2003 | 
 | 
| sl@0 |   2004 | 	sinkBufferSize = theCodec.SinkBufferSize();
 | 
| sl@0 |   2005 | 	pSinkBuffer = CMMFDescriptorBuffer::NewL( sinkBufferSize );
 | 
| sl@0 |   2006 |     CleanupStack::PushL( pSinkBuffer );
 | 
| sl@0 |   2007 | 
 | 
| sl@0 |   2008 | 	pSrcBuffer->Data().SetLength(srcBufferSize);
 | 
| sl@0 |   2009 | 	pDecodedBuffer->Data().SetLength(srcBufferSize);
 | 
| sl@0 |   2010 | 	pSinkBuffer->Data().SetLength(sinkBufferSize);
 | 
| sl@0 |   2011 | 
 | 
| sl@0 |   2012 | 	//[ fill src buffer with ramp] 
 | 
| sl@0 |   2013 | 	FillSrcBufferL( *pSrcBuffer );
 | 
| sl@0 |   2014 |     // encode and decode the data
 | 
| sl@0 |   2015 |     theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer);
 | 
| sl@0 |   2016 | 	theDecoder.ProcessL( *pSinkBuffer, *pDecodedBuffer );
 | 
| sl@0 |   2017 |     
 | 
| sl@0 |   2018 | 	if(!CompareResults( KExpectedSNRatioDb, pSrcBuffer, pDecodedBuffer))
 | 
| sl@0 |   2019 | 		{
 | 
| sl@0 |   2020 | 		//Test has failed because sn ratio was not good enough
 | 
| sl@0 |   2021 | 		result = EFail;
 | 
| sl@0 |   2022 | 		}
 | 
| sl@0 |   2023 | 
 | 
| sl@0 |   2024 | 	//[ clean up ]
 | 
| sl@0 |   2025 | 	CleanupStack::PopAndDestroy( 5, pHwDevice ); // pHwDevice, pHwDecoder, pSrcBuffer, pDecodedBuffer, pSinkBuffer 
 | 
| sl@0 |   2026 | 
 | 
| sl@0 |   2027 | 	__MM_HEAP_MARKEND;
 | 
| sl@0 |   2028 | 	return result;
 | 
| sl@0 |   2029 | 	}
 | 
| sl@0 |   2030 | 
 | 
| sl@0 |   2031 | /**
 | 
| sl@0 |   2032 | *
 | 
| sl@0 |   2033 | * DoTestStepPreambleL
 | 
| sl@0 |   2034 | *
 | 
| sl@0 |   2035 | **/
 | 
| sl@0 |   2036 | TVerdict CTestIMaadCodec::DoTestStepPreambleL(void)
 | 
| sl@0 |   2037 | 	{
 | 
| sl@0 |   2038 |     return EPass;
 | 
| sl@0 |   2039 | 	}
 | 
| sl@0 |   2040 | 
 | 
| sl@0 |   2041 | /**
 | 
| sl@0 |   2042 | *
 | 
| sl@0 |   2043 | * DoTestStepPostambleL
 | 
| sl@0 |   2044 | *
 | 
| sl@0 |   2045 | **/
 | 
| sl@0 |   2046 | TVerdict CTestIMaadCodec::DoTestStepPostambleL(void)
 | 
| sl@0 |   2047 | 	{
 | 
| sl@0 |   2048 |     return EPass;
 | 
| sl@0 |   2049 | 	}
 | 
| sl@0 |   2050 | 
 | 
| sl@0 |   2051 | 
 | 
| sl@0 |   2052 | /**
 | 
| sl@0 |   2053 | *
 | 
| sl@0 |   2054 | * FillSrcBuffer
 | 
| sl@0 |   2055 | * @param aBuffer
 | 
| sl@0 |   2056 | * This function fills the buffer with a ramp of linear pcm16 data
 | 
| sl@0 |   2057 | *
 | 
| sl@0 |   2058 | **/
 | 
| sl@0 |   2059 | void CTestIMaadCodec::FillSrcBufferL( CMMFDescriptorBuffer& aBuffer )
 | 
| sl@0 |   2060 | 	{
 | 
| sl@0 |   2061 | 	 TInt slope = 2;
 | 
| sl@0 |   2062 |      TInt dataLength = aBuffer.Data().Length(); 
 | 
| sl@0 |   2063 | 	 TUint8* pData = const_cast<TUint8*>(aBuffer.Data().Ptr());
 | 
| sl@0 |   2064 | 	 TInt noPc16Samples = dataLength/2;
 | 
| sl@0 |   2065 | 	 ASSERT( noPc16Samples*slope < 32768 );
 | 
| sl@0 |   2066 | 	 for( TInt16 count = 0; count < noPc16Samples ; count++ )
 | 
| sl@0 |   2067 | 		 {
 | 
| sl@0 |   2068 | 		 TInt16 pcmSample = static_cast<TInt16>( count * slope);
 | 
| sl@0 |   2069 |           *pData++ = static_cast<TUint8>( pcmSample & 0xFF );
 | 
| sl@0 |   2070 | 		  *pData++ = static_cast<TUint8>( ( pcmSample >> 8 ));
 | 
| sl@0 |   2071 | 		 }
 | 
| sl@0 |   2072 | 	}
 | 
| sl@0 |   2073 | 
 | 
| sl@0 |   2074 | /**
 | 
| sl@0 |   2075 | *
 | 
| sl@0 |   2076 | * CompareResults
 | 
| sl@0 |   2077 | * @param aExpectedSNRatioDb
 | 
| sl@0 |   2078 | * @param aSrcBuffer
 | 
| sl@0 |   2079 | * @param aSinkBuffer
 | 
| sl@0 |   2080 | * @result TBool
 | 
| sl@0 |   2081 | * This function returns True if the computed Signal to Noise Ratio
 | 
| sl@0 |   2082 | * is Greater than or equal to the expected signal to noise ratio.
 | 
| sl@0 |   2083 | * The function will also return EFalse if any of the preconditions
 | 
| sl@0 |   2084 | * are violated.
 | 
| sl@0 |   2085 | * @precondition aSrcBuffer, aSinkBuffer are not NULL
 | 
| sl@0 |   2086 | * @precondition aSrcBuffer data lenegth == aSinkBuffer data length
 | 
| sl@0 |   2087 | * @precondition the data buffers contain pcm16 data
 | 
| sl@0 |   2088 | * 
 | 
| sl@0 |   2089 | **/
 | 
| sl@0 |   2090 | TBool CTestIMaadCodec::CompareResults( TReal aExpectedSNRatioDb, 
 | 
| sl@0 |   2091 | 			                  CMMFDescriptorBuffer* aSrcBuffer,     
 | 
| sl@0 |   2092 | 		                      CMMFDescriptorBuffer* aSinkBuffer)
 | 
| sl@0 |   2093 | 	{
 | 
| sl@0 |   2094 |      TBool result = EFalse;
 | 
| sl@0 |   2095 | 
 | 
| sl@0 |   2096 | 	 //[ precondition pointers are not NULL ]
 | 
| sl@0 |   2097 | 	 if( !aSrcBuffer || !aSinkBuffer )
 | 
| sl@0 |   2098 | 		 return result;
 | 
| sl@0 |   2099 | 
 | 
| sl@0 |   2100 | 	 //[ precondition buffer lengths are equal ]
 | 
| sl@0 |   2101 |      TInt length = aSrcBuffer->Data().Length();
 | 
| sl@0 |   2102 | 	 if( length != aSinkBuffer->Data().Length() )
 | 
| sl@0 |   2103 | 		 return result;
 | 
| sl@0 |   2104 | 
 | 
| sl@0 |   2105 | 	 // buffers must be of even length
 | 
| sl@0 |   2106 | 	 if( !(length % sizeof(TInt16) == 0 ))
 | 
| sl@0 |   2107 | 		 return result;
 | 
| sl@0 |   2108 | 
 | 
| sl@0 |   2109 |      TInt pcmLength = length/2;
 | 
| sl@0 |   2110 |      TReal sumSignalSquared = 0.0;
 | 
| sl@0 |   2111 | 	 TReal sumNoiseSquared  = 0.0;
 | 
| sl@0 |   2112 |      TUint8* pSrcData = const_cast<TUint8*>(aSrcBuffer->Data().Ptr());
 | 
| sl@0 |   2113 | 	 TUint8* pDecodeData    = const_cast<TUint8*>(aSinkBuffer->Data().Ptr());
 | 
| sl@0 |   2114 |      TInt16 sampleOriginal;
 | 
| sl@0 |   2115 | 	 TInt16 sampleDecode;
 | 
| sl@0 |   2116 | 	 for( TInt count = 0; count < pcmLength; count++ )
 | 
| sl@0 |   2117 | 		 {
 | 
| sl@0 |   2118 | 		  sampleOriginal  = static_cast<TInt16>( pSrcData[0] &KAndMask8bit);  
 | 
| sl@0 |   2119 | 		  sampleOriginal |=  static_cast<TInt16>((pSrcData[1] << 8 ));	
 | 
| sl@0 |   2120 |           sampleDecode    = static_cast<TInt16>( pDecodeData[0] &KAndMask8bit);  
 | 
| sl@0 |   2121 | 		  sampleDecode   |=  static_cast<TInt16>((pDecodeData[1] << 8 )); 
 | 
| sl@0 |   2122 |           pSrcData+=2;
 | 
| sl@0 |   2123 | 		  pDecodeData+= 2;
 | 
| sl@0 |   2124 | 		  sumSignalSquared += sampleOriginal * sampleOriginal;
 | 
| sl@0 |   2125 | 		  TInt noise = sampleOriginal - sampleDecode ;
 | 
| sl@0 |   2126 |           sumNoiseSquared  += noise * noise;
 | 
| sl@0 |   2127 | 		 }
 | 
| sl@0 |   2128 |      
 | 
| sl@0 |   2129 | 	 //[ if the noise is low the signals are equivalent and
 | 
| sl@0 |   2130 | 	 // overflow can be avoided ]
 | 
| sl@0 |   2131 | 	 if( sumNoiseSquared < 0.001 )
 | 
| sl@0 |   2132 | 		 {
 | 
| sl@0 |   2133 | 		 result = ETrue;
 | 
| sl@0 |   2134 | 		 return result;
 | 
| sl@0 |   2135 | 		 }
 | 
| sl@0 |   2136 | 	 TReal computedSNRatioDb;
 | 
| sl@0 |   2137 | 	 Math::Log( computedSNRatioDb, sumSignalSquared/sumNoiseSquared );	 
 | 
| sl@0 |   2138 | 	 computedSNRatioDb *= 10;
 | 
| sl@0 |   2139 | 
 | 
| sl@0 |   2140 | 	 //[ compare claculated s/n ratio against expected ]
 | 
| sl@0 |   2141 |      if( computedSNRatioDb >= aExpectedSNRatioDb )
 | 
| sl@0 |   2142 | 		 result = ETrue;
 | 
| sl@0 |   2143 | 
 | 
| sl@0 |   2144 |      return result;
 | 
| sl@0 |   2145 | 	}
 |