os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_CodecTests.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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 <f32file.h>
sl@0
    20
#include <s32file.h>
sl@0
    21
sl@0
    22
// Test system includes
sl@0
    23
#include "tsu_mmf_CodecTests.h"
sl@0
    24
#include "TSU_MMF_DeviceSuite.h"
sl@0
    25
sl@0
    26
//[codec includes ]
sl@0
    27
#include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
sl@0
    28
#include "MmfPcm16toAlawhwDevice.h"
sl@0
    29
#include "MmfALawToPcm16HwDevice.h"
sl@0
    30
#include "mmfpcm16toMulawhwdevice.h"
sl@0
    31
#include "MmfMuLawToPcm16hwDevice.h"
sl@0
    32
#include "mmfpcmS8ToPcmS16HwDevice.h"
sl@0
    33
#include "mmfpcmS16PcmS8HwDevice.h"
sl@0
    34
#include "mmfpcm16topcmU16BEHwDevice.h"
sl@0
    35
#include "mmfpcm16SwapEndianhwdevice.h"
sl@0
    36
#include "mmfpcm16ToImaAdpcm.h"
sl@0
    37
#include "MmfImaAdpcmtopcm16hwdevice.h"
sl@0
    38
#include "MMFpcm16ToPcm16HwDevice.h"
sl@0
    39
#include "MMFpcm16ToPcmU8HwDevice.h"
sl@0
    40
#include "MMFpcmU8ToPcm16HwDevice.h"
sl@0
    41
#include "mmfpcmS16PcmS8HwDevice.h"
sl@0
    42
sl@0
    43
const TInt KFmtChunkSize = 16;
sl@0
    44
const TInt KAuMagic = 0x2e736e64;
sl@0
    45
sl@0
    46
//[ Codec Unit tests  structure 
sl@0
    47
// The unit tests shall use text files
sl@0
    48
// for small portions of test data 
sl@0
    49
// which should be stored are stored in a simple format
sl@0
    50
// containing the relevant parameters for the test
sl@0
    51
//]
sl@0
    52
class TCodecUnitTestParams
sl@0
    53
	{	
sl@0
    54
public:
sl@0
    55
	const TText* iTestName;       // name of the test
sl@0
    56
	const TText* iInputFilename;  // input wav file
sl@0
    57
	const TText* iComparisonFileName;  // output wav file
sl@0
    58
	TInt		 iExpectedResult; // expected result
sl@0
    59
	};
sl@0
    60
sl@0
    61
// constant table of parameters for tests
sl@0
    62
const TCodecUnitTestParams KTestParameters[] =
sl@0
    63
{	
sl@0
    64
	{ 
sl@0
    65
	_S("MM-MMF-SWCODECDEVICES-U-0010-HP"),   
sl@0
    66
	_S("Pcm16Mono8khz400hzTone.wav"),
sl@0
    67
	_S("Pcm16BMono8Khz400hzTone.Au"),
sl@0
    68
	KErrNone 
sl@0
    69
	},
sl@0
    70
sl@0
    71
	{ 
sl@0
    72
	_S("MM-MMF-SWCODECDEVICES-U-0011-HP"),   
sl@0
    73
	_S("Pcm16Mono8khz400hzTone.wav"),
sl@0
    74
	_S("Imaad4BitMono8Khz400hzTone.wav"),
sl@0
    75
	KErrNone 
sl@0
    76
	},
sl@0
    77
sl@0
    78
	{ 
sl@0
    79
	_S("MM-MMF-SWCODECDEVICES-U-0012-HP"),   
sl@0
    80
	_S("Imaad4BitMono8Khz400hzTone.wav"),
sl@0
    81
	_S("Pcm16Mono8khz400hzTone.wav"),
sl@0
    82
	KErrNone 
sl@0
    83
	},
sl@0
    84
sl@0
    85
	{ 
sl@0
    86
	_S("MM-MMF-SWCODECDEVICES-U-0014-HP"),
sl@0
    87
	_S("Pcm16Mono8khz400hzTone.wav"),
sl@0
    88
	_S("PcmU8Mono8khz400hzTone.wav"),
sl@0
    89
	KErrNone 
sl@0
    90
	},
sl@0
    91
sl@0
    92
	{ 
sl@0
    93
	_S("MM-MMF-SWCODECDEVICES-U-0015-HP"),
sl@0
    94
	_S("PcmU8Mono8khz400hzTone.wav"),
sl@0
    95
	_S("Pcm16Mono8khz400hzTone.wav"),
sl@0
    96
	KErrNone 
sl@0
    97
	},
sl@0
    98
sl@0
    99
	{ 
sl@0
   100
	_S("MM-MMF-SWCODECDEVICES-U-0016-HP"),
sl@0
   101
	_S("Pcm16Stereo8khz400hzTone.wav"),
sl@0
   102
	_S("PcmU8Stereo8khz400hzTone.wav"),
sl@0
   103
	KErrNone 
sl@0
   104
	},
sl@0
   105
};
sl@0
   106
sl@0
   107
/**
sl@0
   108
*
sl@0
   109
* Print8BitResults
sl@0
   110
* @param aRefCodedData
sl@0
   111
* @param aCodedData
sl@0
   112
* @param aDataLength
sl@0
   113
*
sl@0
   114
**/
sl@0
   115
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   116
void CTestStepCodecUnitTest<T,Comparator, A, B, C>::Print8BitResults( TUint8* aRefCodedData, TUint8* aCodedData, TInt aDataLength )
sl@0
   117
	{
sl@0
   118
     __ASSERT_DEBUG(aRefCodedData,Panic(EBadArgument));
sl@0
   119
	 __ASSERT_DEBUG(aCodedData,Panic(EBadArgument));
sl@0
   120
sl@0
   121
	for( TInt i = 0; i < aDataLength; i++ )
sl@0
   122
		{
sl@0
   123
        INFO_PRINTF6( _L("delta %u p1 %u p2 %u p1 %x p2 %x"), (*aRefCodedData-*aCodedData),*aRefCodedData, *aCodedData, *aRefCodedData, *aCodedData );
sl@0
   124
		aRefCodedData++;
sl@0
   125
		aCodedData++;
sl@0
   126
		}
sl@0
   127
	}
sl@0
   128
sl@0
   129
/**
sl@0
   130
*
sl@0
   131
* Print16BitResults
sl@0
   132
* @param aRefCodedData
sl@0
   133
* @param aCodedData
sl@0
   134
* @param aDataLength
sl@0
   135
*
sl@0
   136
**/
sl@0
   137
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   138
void CTestStepCodecUnitTest<T,Comparator, A, B, C>::Print16BitResults( TUint8* aRefCodedData, TUint8* aCodedData, TInt aDataLength )
sl@0
   139
	{
sl@0
   140
	//[precondition pointers are aok]
sl@0
   141
     __ASSERT_DEBUG(aRefCodedData,Panic(EBadArgument));
sl@0
   142
	 __ASSERT_DEBUG(aCodedData,Panic(EBadArgument));
sl@0
   143
	 //[precondition data is of even length ]
sl@0
   144
	 __ASSERT_DEBUG( (aDataLength % 2 == 0),Panic(EBadArgument));
sl@0
   145
	
sl@0
   146
	TInt length = aDataLength /2;
sl@0
   147
	TInt16 refCodedValue = 0;
sl@0
   148
	TInt16 codedValue = 0;
sl@0
   149
	for( TInt i = 0; i < length; i++ )
sl@0
   150
		{
sl@0
   151
		refCodedValue  = static_cast<TInt16>( aRefCodedData[0] );  
sl@0
   152
		refCodedValue |=  static_cast<TInt16>((aRefCodedData[1] << 8 ));
sl@0
   153
		codedValue  = static_cast<TInt16>( aCodedData[0] &KAndMask8bit);  
sl@0
   154
		codedValue |=  static_cast<TInt16>((aCodedData[1] << 8 ));
sl@0
   155
        INFO_PRINTF6( _L("delta %d p1 %d p2 %d p1 %x p2 %x"), (refCodedValue-codedValue),refCodedValue, codedValue, refCodedValue, codedValue );
sl@0
   156
		aRefCodedData+=2;
sl@0
   157
		aCodedData+=2;
sl@0
   158
		}
sl@0
   159
	}
sl@0
   160
/**
sl@0
   161
*
sl@0
   162
* CTestStepCodecUnitTest
sl@0
   163
*
sl@0
   164
**/
sl@0
   165
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   166
CTestStepCodecUnitTest<T,Comparator, A, B, C>::CTestStepCodecUnitTest( TUint aTestIndex )
sl@0
   167
	{
sl@0
   168
	//[precondition valid index ]
sl@0
   169
//	__ASSERT_DEBUG( (aTestIndex >= 0),Panic(EBadArgument));	// EABI warning removal
sl@0
   170
	__ASSERT_DEBUG( (aTestIndex < (sizeof(KTestParameters)/sizeof(TCodecUnitTestParams))),Panic(EBadArgument));
sl@0
   171
	// store a pointer to the test parameters
sl@0
   172
	iTestParameters = &(KTestParameters[aTestIndex]);
sl@0
   173
	// store the name of this test case
sl@0
   174
	// this is the name that is used by the script file
sl@0
   175
	iTestStepName = iTestParameters->iTestName;
sl@0
   176
	}
sl@0
   177
sl@0
   178
/**
sl@0
   179
*
sl@0
   180
* ~CTestStepCodecUnitTest
sl@0
   181
*
sl@0
   182
**/
sl@0
   183
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   184
CTestStepCodecUnitTest<T,Comparator, A, B, C>::~CTestStepCodecUnitTest()
sl@0
   185
	{
sl@0
   186
	}
sl@0
   187
/**
sl@0
   188
*
sl@0
   189
* DoTestStepL
sl@0
   190
*
sl@0
   191
**/
sl@0
   192
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   193
TVerdict CTestStepCodecUnitTest<T,Comparator, A, B, C>::DoTestStepL()
sl@0
   194
	{
sl@0
   195
	__MM_HEAP_MARK;
sl@0
   196
	TVerdict result = EPass;
sl@0
   197
sl@0
   198
	// code and decode the input file
sl@0
   199
    TInt numBuffersToProcess = ComputeBuffersToProcess();
sl@0
   200
	TInt codedBufferSize = numBuffersToProcess*iCodecUnderTest->SinkBufferSize();
sl@0
   201
	iCodedData = CMMFDescriptorBuffer::NewL( codedBufferSize);
sl@0
   202
	// Compare the results and return test status
sl@0
   203
	TUint8* ptrSrc  = CONST_CAST(TUint8*,iSourceData->Data().Ptr());
sl@0
   204
	TUint8* ptrDest = CONST_CAST(TUint8*,iCodedData->Data().Ptr());
sl@0
   205
    CMMFDataBuffer* srcBuffer = CMMFDescriptorBuffer::NewL(iCodecUnderTest->SourceBufferSize());
sl@0
   206
	CleanupStack::PushL(srcBuffer);
sl@0
   207
	CMMFDataBuffer* destBuffer = CMMFDescriptorBuffer::NewL(iCodecUnderTest->SinkBufferSize());
sl@0
   208
	TUint8* pInBuffer  = CONST_CAST(TUint8*,srcBuffer->Data().Ptr());
sl@0
   209
    TUint8* pOutBuffer = CONST_CAST(TUint8*,destBuffer->Data().Ptr());
sl@0
   210
	CleanupStack::PushL(destBuffer);
sl@0
   211
sl@0
   212
	for( TInt i = 0; i < numBuffersToProcess;  i++)
sl@0
   213
		{
sl@0
   214
         //[ copy data & increment input pointer]
sl@0
   215
		Mem::Copy( pInBuffer, ptrSrc, iCodecUnderTest->SourceBufferSize() );
sl@0
   216
		srcBuffer->Data().SetLength( iCodecUnderTest->SourceBufferSize() );
sl@0
   217
		ptrSrc+= iCodecUnderTest->SourceBufferSize();
sl@0
   218
sl@0
   219
		 //[ code the data ]
sl@0
   220
		iCodecUnderTest->ProcessL( *srcBuffer, *destBuffer);
sl@0
   221
sl@0
   222
		 //[ copy out the data & increment pointer ]
sl@0
   223
		Mem::Copy( ptrDest, pOutBuffer, iCodecUnderTest->SinkBufferSize() );
sl@0
   224
        iCodedData->Data().SetLength( (i+1)*iCodecUnderTest->SinkBufferSize() );
sl@0
   225
		destBuffer->Data().SetLength(0); // reset buffer length
sl@0
   226
		ptrDest+=iCodecUnderTest->SinkBufferSize();
sl@0
   227
		}
sl@0
   228
sl@0
   229
	//[ compare the coded data against the reference data]
sl@0
   230
	//[ compare the processed number of bytes in the 
sl@0
   231
	// coded buffer to the reference data]
sl@0
   232
	__ASSERT_DEBUG( iRefCodedData->Data().Length() >= iCodedData->Data().Length(),Panic(EBadInvariant));
sl@0
   233
   
sl@0
   234
	TUint8* ptr1 = CONST_CAST(TUint8*,iRefCodedData->Data().Ptr());
sl@0
   235
	TUint8* ptr2 = CONST_CAST(TUint8*,iCodedData->Data().Ptr());
sl@0
   236
sl@0
   237
	if(!iComparator.CompareL( ptr1,ptr2, iCodedData->Data().Length())!=0)
sl@0
   238
		{
sl@0
   239
		 INFO_PRINTF1( _L("Comparison has failed"));
sl@0
   240
		//(this->*iPrintFormats[ C ])( ptr1, ptr2, iCodedData->Data().Length() );
sl@0
   241
		result = EFail ;
sl@0
   242
		}
sl@0
   243
sl@0
   244
	//[ pop buffers ]
sl@0
   245
	CleanupStack::PopAndDestroy(2,srcBuffer); //srcBuffer, destBuffer
sl@0
   246
	delete iCodedData;
sl@0
   247
	iCodedData = NULL;
sl@0
   248
sl@0
   249
	__MM_HEAP_MARKEND;
sl@0
   250
	return result;
sl@0
   251
	}
sl@0
   252
sl@0
   253
/**
sl@0
   254
*
sl@0
   255
* DoTestStepPreambleL
sl@0
   256
*
sl@0
   257
**/
sl@0
   258
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   259
TVerdict CTestStepCodecUnitTest<T,Comparator,A,B, C>::DoTestStepPreambleL()
sl@0
   260
	{
sl@0
   261
	//[ assert preconditions on a and b ]
sl@0
   262
	__ASSERT_DEBUG( A >= 0, Panic(EBadInvariant)); //sanity check on data
sl@0
   263
	__ASSERT_DEBUG( B >= 0, Panic(EBadInvariant)); //sanity check on data
sl@0
   264
	__ASSERT_DEBUG( C >= 0, Panic(EBadInvariant)); //sanity check on data
sl@0
   265
	__ASSERT_DEBUG( A < 2, Panic(EBadInvariant)); //sanity check on data
sl@0
   266
	__ASSERT_DEBUG( B < 2, Panic(EBadInvariant)); //sanity check on data
sl@0
   267
	__ASSERT_DEBUG( C < 2, Panic(EBadInvariant)); //sanity check on data
sl@0
   268
sl@0
   269
	//[ initialise file reader callbacks ]
sl@0
   270
	iReaders[ 0 ] = &CTestStepCodecUnitTest<T,Comparator,A,B,C>::ReadWavFileL;
sl@0
   271
    iReaders[ 1 ] = &CTestStepCodecUnitTest<T,Comparator,A,B,C>::ReadAuFileL;
sl@0
   272
   
sl@0
   273
	//[ initialise print format callbacks ]
sl@0
   274
	iPrintFormats[ 0 ] = &CTestStepCodecUnitTest<T,Comparator,A,B,C>::Print8BitResults;
sl@0
   275
    iPrintFormats[ 1 ] = &CTestStepCodecUnitTest<T,Comparator,A,B,C>::Print16BitResults;
sl@0
   276
   
sl@0
   277
    // make codec
sl@0
   278
	iCodecUnderTest = new(ELeave) T; // a cmmfcodec 
sl@0
   279
	
sl@0
   280
	// [ Parse files into buffers, input & comparison
sl@0
   281
	//   using the configured file readers ]
sl@0
   282
	TBuf<40> testFileName = iTestParameters->iInputFilename;
sl@0
   283
	(this->*iReaders[ A ])(iSourceData, testFileName );
sl@0
   284
	testFileName = iTestParameters->iComparisonFileName;
sl@0
   285
    (this->*iReaders[ B ])(iRefCodedData,testFileName );
sl@0
   286
	return EPass;
sl@0
   287
	}
sl@0
   288
/**
sl@0
   289
*
sl@0
   290
* DoTestStepPostambleL
sl@0
   291
*
sl@0
   292
**/
sl@0
   293
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   294
TVerdict CTestStepCodecUnitTest<T,Comparator, A, B, C>::DoTestStepPostambleL(void)
sl@0
   295
	{
sl@0
   296
    //Destroy Codec
sl@0
   297
    delete iCodecUnderTest;
sl@0
   298
	delete iSourceData;  
sl@0
   299
	delete iCodedData;   
sl@0
   300
	delete iRefCodedData;
sl@0
   301
	return EPass;
sl@0
   302
	}
sl@0
   303
sl@0
   304
/**
sl@0
   305
* Reads wav file data into the supplied buffer
sl@0
   306
* ReadFileL
sl@0
   307
* @param
sl@0
   308
* @param
sl@0
   309
* This function reads the data portion of a wav file
sl@0
   310
* into a data buffer
sl@0
   311
**/
sl@0
   312
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   313
void CTestStepCodecUnitTest<T,Comparator, A, B, C>::ReadWavFileL( CMMFDataBuffer* &aBuffer, const TDesC& aFile )
sl@0
   314
	{
sl@0
   315
	// connect to the file server
sl@0
   316
	User::LeaveIfError(iFs.Connect());
sl@0
   317
	
sl@0
   318
	// [open the file and read its data contents into the buffer ]
sl@0
   319
	// [the assumption will be the data is stored in wav format only]
sl@0
   320
	TFileName fileName = GetSuite()->DefaultPath();
sl@0
   321
	fileName.Append(aFile);
sl@0
   322
sl@0
   323
	RFile file1;
sl@0
   324
	User::LeaveIfError(file1.Open(iFs, fileName, EFileShareAny | EFileStream | EFileRead));
sl@0
   325
	CleanupClosePushL(file1);
sl@0
   326
sl@0
   327
    //[ get the size and position of the data from the wav file ]
sl@0
   328
	TInt pos  = KFmtChunkSize;
sl@0
   329
	User::LeaveIfError(file1.Seek( ESeekStart, pos ));
sl@0
   330
	TInt fmtChunkSize = 0;
sl@0
   331
	User::LeaveIfError(ReadInt(file1, fmtChunkSize));
sl@0
   332
	//[ seek to data chunk size ]
sl@0
   333
    pos = KFmtChunkSize+fmtChunkSize+8;
sl@0
   334
	User::LeaveIfError(file1.Seek(ESeekStart, pos ));    
sl@0
   335
	//read data chunk size
sl@0
   336
	TInt dataChunkSize = 0;
sl@0
   337
	User::LeaveIfError(ReadInt(file1, dataChunkSize));
sl@0
   338
    //create buffer large eneough to deal with data size
sl@0
   339
	TInt fileSize = 0;
sl@0
   340
	User::LeaveIfError(file1.Size(fileSize));
sl@0
   341
	__ASSERT_DEBUG( fileSize > dataChunkSize, Panic(EBadInvariant)); //sanity check on data
sl@0
   342
	aBuffer = CMMFDescriptorBuffer::NewL(dataChunkSize);
sl@0
   343
	User::LeaveIfError(file1.Read( aBuffer->Data(),dataChunkSize));
sl@0
   344
	aBuffer->Data().SetLength(dataChunkSize);
sl@0
   345
	file1.Close();
sl@0
   346
	CleanupStack::PopAndDestroy(1); //file1
sl@0
   347
	}
sl@0
   348
sl@0
   349
/**
sl@0
   350
* Reads Au file data into the supplied buffer
sl@0
   351
* ReadFileL
sl@0
   352
* @param
sl@0
   353
* @param
sl@0
   354
* This function reads the data portion of a wav file
sl@0
   355
* into a data buffer
sl@0
   356
**/
sl@0
   357
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   358
void CTestStepCodecUnitTest<T,Comparator, A, B, C>::ReadAuFileL( CMMFDataBuffer* &aBuffer, const TDesC& aFile )
sl@0
   359
	{
sl@0
   360
	// connect to the file server
sl@0
   361
	User::LeaveIfError(iFs.Connect());
sl@0
   362
	
sl@0
   363
	// [open the file and read its data contents into the buffer ]
sl@0
   364
	TFileName fileName = GetSuite()->DefaultPath();
sl@0
   365
	fileName.Append(aFile);
sl@0
   366
sl@0
   367
	RFile file1;
sl@0
   368
	User::LeaveIfError(file1.Open(iFs, fileName, EFileShareAny | EFileStream | EFileRead));
sl@0
   369
	CleanupClosePushL(file1);
sl@0
   370
     
sl@0
   371
  	TInt magicNumber = 0;
sl@0
   372
	User::LeaveIfError(ReadIntB(file1, magicNumber));
sl@0
   373
    if( magicNumber != KAuMagic )
sl@0
   374
		{
sl@0
   375
         // have not detected the appropriate header
sl@0
   376
		 INFO_PRINTF1(_L("Have not detected Au Header ie magic number 0x2e736e64"));
sl@0
   377
		 User::Leave( KErrCorrupt );
sl@0
   378
		}
sl@0
   379
sl@0
   380
	//[ header size ]
sl@0
   381
    TInt headerSize = 0;
sl@0
   382
	User::LeaveIfError(ReadIntB(file1, headerSize));
sl@0
   383
sl@0
   384
	TInt fileSize = 0;
sl@0
   385
	User::LeaveIfError(file1.Size(fileSize));
sl@0
   386
sl@0
   387
    //[ filesize - headersize = datasize ]
sl@0
   388
    TInt dataSize = fileSize - headerSize;
sl@0
   389
sl@0
   390
    // [ assert that the datasize >= 0 ]
sl@0
   391
	__ASSERT_DEBUG( dataSize >= 0, Panic(EBadInvariant)); //sanity check on data
sl@0
   392
sl@0
   393
	//[Seek to the correct position and read data into Buffer]
sl@0
   394
	User::LeaveIfError(file1.Seek(ESeekStart, headerSize )); 
sl@0
   395
	__ASSERT_DEBUG( fileSize > dataSize, Panic(EBadInvariant)); //sanity check on data
sl@0
   396
sl@0
   397
	//[ read the data into a Buffer ]
sl@0
   398
	aBuffer = CMMFDescriptorBuffer::NewL(dataSize);
sl@0
   399
	User::LeaveIfError(file1.Read( aBuffer->Data(),dataSize));
sl@0
   400
	aBuffer->Data().SetLength(dataSize);
sl@0
   401
	file1.Close();
sl@0
   402
	CleanupStack::PopAndDestroy(1); //file1
sl@0
   403
	}
sl@0
   404
sl@0
   405
/**
sl@0
   406
* Reads file into buffer
sl@0
   407
* ReadFileL
sl@0
   408
* @param aFile the file from which to read the data
sl@0
   409
* @param aValue the returned value
sl@0
   410
* This function reads a 32bit value in a rather inefficient way
sl@0
   411
**/
sl@0
   412
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   413
TInt CTestStepCodecUnitTest<T,Comparator, A, B, C>::ReadInt( RFile& aFile, TInt& aValue )
sl@0
   414
	{
sl@0
   415
	 TUint8 data[4];
sl@0
   416
     TPtr8 theDes( data, 4 ); 
sl@0
   417
 	 User::LeaveIfError(aFile.Read( theDes, 4));
sl@0
   418
     // now assemble the data from the buffer
sl@0
   419
     aValue  = data[0];
sl@0
   420
	 aValue |= data[1] << 8;
sl@0
   421
	 aValue |= data[2] << 16;
sl@0
   422
	 aValue |= data[3] << 24;
sl@0
   423
	 
sl@0
   424
	 return KErrNone;
sl@0
   425
	}
sl@0
   426
sl@0
   427
sl@0
   428
/**
sl@0
   429
* Reads file into buffer
sl@0
   430
* ReadFileL
sl@0
   431
* @param aFile the file from which to read the data
sl@0
   432
* @param aValue the returned value
sl@0
   433
* This function reads a 32bit value in BigEndian forma
sl@0
   434
and coverts it to Little Endian in a rather inefficient way
sl@0
   435
**/
sl@0
   436
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   437
TInt CTestStepCodecUnitTest<T,Comparator, A, B, C>::ReadIntB( RFile& aFile, TInt& aValue )
sl@0
   438
	{
sl@0
   439
	 TUint8 data[4];
sl@0
   440
     TPtr8 theDes( data, 4 ); 
sl@0
   441
 	 User::LeaveIfError(aFile.Read( theDes, 4));
sl@0
   442
     // now assemble the data from the buffer
sl@0
   443
     aValue  = data[3];
sl@0
   444
	 aValue |= data[2] << 8;
sl@0
   445
	 aValue |= data[1] << 16;
sl@0
   446
	 aValue |= data[0] << 24;
sl@0
   447
	 
sl@0
   448
	 return KErrNone;
sl@0
   449
	}
sl@0
   450
sl@0
   451
/**
sl@0
   452
*
sl@0
   453
* ComputeBuffersToProcess
sl@0
   454
* @precondition InputBuffer has been setup
sl@0
   455
* @precondition Codec has been instantiated
sl@0
   456
*
sl@0
   457
**/
sl@0
   458
template <class T, class Comparator, TInt A, TInt B, TInt C>
sl@0
   459
TInt CTestStepCodecUnitTest<T,Comparator, A, B, C>::ComputeBuffersToProcess()
sl@0
   460
	{
sl@0
   461
   	TInt numWholeBuffers = (iSourceData->Data().MaxLength()/iCodecUnderTest->SourceBufferSize() );
sl@0
   462
	return numWholeBuffers;
sl@0
   463
    }
sl@0
   464
sl@0
   465
sl@0
   466
/**
sl@0
   467
*
sl@0
   468
* This is used for template instantiation.
sl@0
   469
*
sl@0
   470
**/
sl@0
   471
sl@0
   472
template class CTestStepCodecUnitTest<CMMFPcm16SwapEndianCodec,TComparator,0,1,1>;
sl@0
   473
template class CTestStepCodecUnitTest<CMMFPcm16ToImaAdpcmCodec,TComparator>;
sl@0
   474
template class CTestStepCodecUnitTest<CMMFImaAdpcmToPcm16Codec,TDbComparator<>,0,0,1>;
sl@0
   475
template class CTestStepCodecUnitTest<CMMFPcm16ToPcmU8Codec,TComparator>;
sl@0
   476
template class CTestStepCodecUnitTest<CMMFPcmU8ToPcm16Codec,TDbComparator<>,0,0,1>;
sl@0
   477
sl@0
   478
sl@0
   479
/**
sl@0
   480
*
sl@0
   481
* Compare
sl@0
   482
* @param aData
sl@0
   483
* @param aData2
sl@0
   484
* @param aNoSamples
sl@0
   485
* @return TBool
sl@0
   486
*
sl@0
   487
**/
sl@0
   488
TBool TComparator::CompareL( TUint8* aData, TUint8* aData2, TInt aLength )
sl@0
   489
	{
sl@0
   490
	TBool result = ETrue;
sl@0
   491
    if( !aData )
sl@0
   492
		User::Leave(KErrArgument);
sl@0
   493
	if( !aData2 )
sl@0
   494
		User::Leave(KErrArgument);
sl@0
   495
sl@0
   496
	if( Mem::Compare( aData,aLength, aData2, aLength )!=0)
sl@0
   497
		{
sl@0
   498
		result = EFalse;
sl@0
   499
		}
sl@0
   500
sl@0
   501
	return result;
sl@0
   502
	}
sl@0
   503
sl@0
   504
/**
sl@0
   505
*
sl@0
   506
* Compare
sl@0
   507
* @param aData
sl@0
   508
* @param aData2
sl@0
   509
* @param aNoSamples
sl@0
   510
* @result TBool
sl@0
   511
*
sl@0
   512
**/
sl@0
   513
template <TInt T>
sl@0
   514
TBool TDbComparator<T>::CompareL( TUint8* aData, TUint8* aData2, TInt aLength )
sl@0
   515
	{
sl@0
   516
	TBool result = ETrue;
sl@0
   517
    if( !aData )
sl@0
   518
		User::Leave(KErrArgument);
sl@0
   519
	if( !aData2 )
sl@0
   520
		User::Leave(KErrArgument);
sl@0
   521
sl@0
   522
    //[ lets compute the signal to noise ratio ]
sl@0
   523
    TReal sumSigSquared   = 0.0;
sl@0
   524
	TReal sumErrorSquared = 0.0;
sl@0
   525
	TUint8* pData = aData;
sl@0
   526
	TUint8* pData2 = aData2;
sl@0
   527
	TInt numSamples = aLength/2;
sl@0
   528
	// compute the sum of sig and error squared
sl@0
   529
	for( TInt count = 0; count < numSamples; count++ )
sl@0
   530
		{
sl@0
   531
		TInt16 sample1  = static_cast<TInt16>( pData[0] &KAndMask8bit);  
sl@0
   532
		       sample1 |=  static_cast<TInt16>((pData[1] << 8 ));
sl@0
   533
		TInt16 sample2  = static_cast<TInt16>( pData2[0] &KAndMask8bit);  
sl@0
   534
		       sample2 |=  static_cast<TInt16>((pData2[1] << 8 ));
sl@0
   535
			   pData +=1;
sl@0
   536
			   pData2+=2;
sl@0
   537
		sumSigSquared   += sample1*sample1;
sl@0
   538
		sumErrorSquared += (sample1-sample2)*(sample1-sample2);
sl@0
   539
		}
sl@0
   540
sl@0
   541
	TReal sn = 0.0;
sl@0
   542
	const TReal tolerance = 0.001;
sl@0
   543
	//[precondition error is >= tolerance ]
sl@0
   544
	if( sumErrorSquared < tolerance )
sl@0
   545
		User::Leave( KErrArgument );
sl@0
   546
	//[claculate ratio safely ]
sl@0
   547
	Math::Log( sn, (sumSigSquared/sumErrorSquared));
sl@0
   548
	sn*= 10;
sl@0
   549
	TReal threshold = T; // integer used as real with 100ths db accuracy
sl@0
   550
	      threshold /= 100.0;
sl@0
   551
	if( sn < threshold )
sl@0
   552
		result = EFalse;
sl@0
   553
	
sl@0
   554
	return result;
sl@0
   555
	}
sl@0
   556