os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_SignConversionCodecs.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // TSU_MMF_CodecTests.cpp
    15 // 
    16 //
    17 
    18 // EPOC includes
    19 #include <e32base.h>
    20 #include <e32math.h>
    21 #include <f32file.h>
    22 #include <s32file.h>
    23 
    24 // Test system includes
    25 #include "TSU_MMF_DeviceSuite.h"
    26 #include "TSU_MMF_SignConversionCodecs.h"
    27 
    28 //[ codec includes ]
    29 #include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
    30 #include "MmfPcm16toAlawhwDevice.h"
    31 #include "MmfALawToPcm16HwDevice.h"
    32 #include "mmfpcm16toMulawhwdevice.h"
    33 #include "MmfMuLawToPcm16hwDevice.h"
    34 #include "mmfpcmS8ToPcmS16HwDevice.h"
    35 #include "mmfpcmS16PcmS8HwDevice.h"
    36 #include "mmfpcm16topcmU16BEHwDevice.h"
    37 #include "mmfpcm16SwapEndianhwdevice.h"
    38 #include "mmfpcm16ToImaAdpcm.h"
    39 #include "MmfImaAdpcmtopcm16hwdevice.h"
    40 #include "MMFpcm16ToPcm16HwDevice.h"
    41 #include "MMFpcm16ToPcmU8HwDevice.h"
    42 #include "MMFpcmU8ToPcm16HwDevice.h"
    43 #include "mmfpcmS16PcmS8HwDevice.h"
    44 
    45 
    46 //[ Codec Unit tests  structure 
    47 // The unit tests shall use text files
    48 // for small portions of test data 
    49 // which should be stored are stored in a simple format
    50 // containing the relevant parameters for the test
    51 //]
    52 class TSignConversionTestParams
    53 	{	
    54 public:
    55 	const TText* iTestName;       // name of the test
    56 	};
    57 
    58 // constant table of parameters for tests
    59 const TSignConversionTestParams KSignConversionParameters[] =
    60 	{	
    61 		{_S("MM-MMF-SWCODECDEVICES-U-0017-HP")},
    62 		{_S("MM-MMF-SWCODECDEVICES-U-0018-HP")},
    63 		{_S("MM-MMF-SWCODECDEVICES-U-0019-HP")},
    64 		{_S("MM-MMF-SWCODECDEVICES-U-0020-HP")}, 
    65 		{_S("MM-MMF-SWCODECDEVICES-U-0021-HP")}
    66 	};
    67 
    68 /**
    69 *
    70 * PrintComparisonDataL
    71 * @param aCodedData the coded data buffer
    72 * @param aRefCodedData the reference coded data buffer
    73 * 
    74 */
    75 void CMMFDataGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
    76 	{
    77 	//[precondition reference coded data is equal in size or longer than coded data ]
    78 	if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
    79 		{
    80          //[coded data is longer than reference data]
    81 	//	RDebug::Print(_L("Coded Data is longer than refernce data")); Commented under DEF105143
    82 		User::Leave( KErrCorrupt );	 
    83 		}
    84 
    85 	TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
    86 	TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
    87     TInt length = aCodedData.Data().Length();
    88 	//[ now print the results for comparison ]
    89 	for( TInt i = 0; i < length; i++ )
    90 		{
    91         RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (*ptr1-*ptr2), *ptr1++, *ptr2++ );
    92 		} 
    93 	}
    94 
    95 /**
    96 *
    97 * AssembleValue
    98 * @param aData src data buffer 
    99 * @param aValue resultant value
   100 * @param aBigEndian whether the value is in BigEndian format
   101 * @precondition aData is not null and has length >= 2
   102 *
   103 */
   104 void CMMFDataGenerator::AssembleValue( TUint8* aData, TInt16& aValue, TBool aBigEndian )
   105 	{
   106 	__ASSERT_DEBUG( aData, Panic(EBadArgument));
   107     if( aBigEndian )
   108 		{
   109 		aValue  = static_cast<TInt16>( aData[1] &KAndMask8bit );  
   110 		aValue |=  static_cast<TInt16>((aData[0] << 8 ));
   111 		}
   112 	else
   113 		{
   114 		aValue  = static_cast<TInt16>( aData[0] &KAndMask8bit);  
   115 		aValue |=  static_cast<TInt16>((aData[1] << 8 ));
   116 		}
   117 	}
   118 
   119 /**
   120 *
   121 * AssembleValue
   122 * @param aData src data buffer 
   123 * @param aValue resultant value
   124 * @param aBigEndian whether the value is in BigEndian format
   125 * @precondition aData is not null and has length >= 2
   126 *
   127 */
   128 void CMMFDataGenerator::AssembleValue( TUint8* aData, TUint16& aValue, TBool aBigEndian )
   129 	{
   130 	__ASSERT_DEBUG( aData, Panic(EBadArgument));
   131 	if( aBigEndian )
   132 		{
   133 		aValue     = aData[1] ; //[ big endian format]
   134 		aValue    |= (aData[0] << 8 ); 
   135 		}
   136 	else
   137 		{
   138 		aValue     = aData[0] ; 
   139 		aValue    |= (aData[1] << 8 ); 
   140 		}
   141 	}
   142 /**
   143 *
   144 * CMMFPcmU16toPcmU16BGenerator
   145 *
   146 **/
   147 CMMFPcmU16toPcmU16BGenerator::CMMFPcmU16toPcmU16BGenerator()
   148 	{
   149 	}
   150 
   151 /**
   152 *
   153 * ~CMMFPcmU16toPcmU16BGenerator
   154 *
   155 **/
   156 CMMFPcmU16toPcmU16BGenerator::~CMMFPcmU16toPcmU16BGenerator()
   157 	{
   158 	}
   159 
   160 /**
   161 *
   162 * GenerateSourceDataL
   163 *
   164 **/
   165 void CMMFPcmU16toPcmU16BGenerator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   166 	{
   167 	const TUint16 KScale2 = 32000;
   168 
   169 	 //[ create a buffer large enough to fill with the data ]
   170 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   171 
   172 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   173 
   174 	//[ lets fill it with a 400hz signal at approx -3db ]
   175 	//[encode the data]
   176 	 TUint16 srcValue = 0;
   177 	 TReal val   = 0.0;
   178 	 TReal theta = 0.0; 
   179 
   180 	 TInt noSamples = aSize/sizeof(TInt16);
   181 	 for(TInt i=0; i< noSamples; i++)
   182 		 {
   183 		 //[ assign data and place in buffer]
   184 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   185 		                      // better reproduction through gsm codec
   186 		  User::LeaveIfError(Math::Sin(val,theta));
   187           srcValue = static_cast<TUint16>( (KScale2 * val ) + KScale2+0.5);
   188           *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
   189 		  *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
   190 		 }
   191     
   192 	 aBuffer->Data().SetLength(aSize); 
   193 	}
   194 
   195 /**
   196 *
   197 * GenerateComparisonDataL
   198 *
   199 **/
   200 void CMMFPcmU16toPcmU16BGenerator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   201 	{
   202 	const TUint16 KScale2 = 32000;
   203 
   204 	 //[ create a buffer large eneough to fill with the data ]
   205 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   206 
   207 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   208 
   209 	//[ lets fill it with a 400hz signal at approx -3db ]
   210 	//[encode the data]
   211 	 TUint16 srcValue = 0;
   212 	 TReal val   = 0.0;
   213 	 TReal theta = 0.0; 
   214 
   215 	 TInt noSamples = aSize/sizeof(TInt16);
   216 	 for(TInt i=0; i< noSamples; i++)
   217 		 {
   218 		 //[ assign data and place in buffer]
   219 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   220 		                      // better reproduction through gsm codec
   221 		  User::LeaveIfError(Math::Sin(val,theta));
   222           srcValue = static_cast<TUint16>( (KScale2 * val)+KScale2 +0.5);
   223           //[endian swap here ]
   224 		  *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
   225 		  *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
   226 		 }
   227     
   228 	 aBuffer->Data().SetLength(aSize); 
   229 	}
   230 
   231 /**
   232 *
   233 * PrintComparisonDataL
   234 * Prints out coded results for comparison with the 
   235 * Reference values and is used when the results differ
   236 *
   237 **/
   238 void CMMFPcmU16toPcmU16BGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
   239 	{
   240 	//[precondition reference coded data is equal in size or longer than coded data ]
   241 	if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
   242 		{
   243          //[coded data is longer than reference data]
   244 	//	RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
   245 		User::Leave( KErrCorrupt );	 
   246 		}
   247 
   248 	//[ now print the results for comparison ]
   249     TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
   250 	TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
   251     TInt length = aCodedData.Data().Length();
   252 	length /= 2; // [for 16bit words length is half]
   253 	//[ assert invariant length is even ]
   254 	__ASSERT_DEBUG( (length % 2 == 0 ), Panic(EBadInvariant));
   255 
   256 	TUint16 codedValue = 0;
   257 	TUint16 refCodedValue = 0;
   258 	//[ now print the results for comparison ]
   259 	for( TInt i = 0; i < length; i++ )
   260 		{
   261 		//[ assemble 16bit values from buffer values ]    
   262 		AssembleValue( ptr1, codedValue, ETrue );
   263 		AssembleValue( ptr2, refCodedValue, ETrue );       
   264 		RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue );
   265 		if( i % 100 == 0 ) //deal with debug printf deficiencies
   266 			{
   267 			User::After(100 );
   268 			}
   269 		ptr1+=2;
   270 		ptr2+=2;
   271 		} 
   272  	}
   273 
   274 /**
   275 *
   276 * CMMFPcmU16BtoPcmU16Generator
   277 *
   278 **/
   279 CMMFPcmU16BtoPcmU16Generator::CMMFPcmU16BtoPcmU16Generator()
   280 	{
   281 	}
   282 
   283 /**
   284 *
   285 * ~CMMFPcmU16BtoPcmU16Generator
   286 *
   287 **/
   288 CMMFPcmU16BtoPcmU16Generator::~CMMFPcmU16BtoPcmU16Generator()
   289 	{
   290 	}
   291 
   292 /**
   293 *
   294 * GenerateSourceDataL
   295 *
   296 **/
   297 void CMMFPcmU16BtoPcmU16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   298 	{
   299 	const TUint8 KScale2 = 127;
   300 
   301 	 //[ create a buffer large eneough to fill with the data ]
   302 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   303 
   304 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   305 
   306 	//[ lets fill it with a 400hz signal at approx -3db ]
   307 	//[encode the data]
   308 	 TInt8 srcValue = 0;
   309 	 TReal val   = 0.0;
   310 	 TReal theta = 0.0; 
   311 
   312 	 TInt noSamples = aSize/sizeof(TInt16);
   313 	 for(TInt i=0; i< noSamples; i++)
   314 		 {
   315 		 //[ assign data and place in buffer]
   316 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   317 		                      // better reproduction through gsm codec
   318 		  User::LeaveIfError(Math::Sin(val,theta));
   319           srcValue = static_cast<TUint8>( (KScale2 * val) );
   320           //[endian swap here ]
   321 		  *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
   322 		  *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
   323 		 }
   324     
   325 	 aBuffer->Data().SetLength(aSize); 
   326 	}
   327 
   328 /**
   329 *
   330 * GenerateComparisonDataL
   331 *
   332 **/
   333 void CMMFPcmU16BtoPcmU16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   334 	{
   335 	const TUint8 KScale2 = 127;
   336 
   337 	 //[ create a buffer large eneough to fill with the data ]
   338 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   339 
   340 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   341 
   342 	//[ lets fill it with a 400hz signal at approx -3db ]
   343 	//[encode the data]
   344 	 TUint16 srcValue = 0;
   345 	 TReal val   = 0.0;
   346 	 TReal theta = 0.0; 
   347 	 TInt noSamples = aSize/sizeof(TInt16);
   348 	 for(TInt i=0; i< noSamples; i++)
   349 		 {
   350 		 //[ assign data and place in buffer]
   351 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   352 		                      // better reproduction through gsm codec
   353 		  User::LeaveIfError(Math::Sin(val,theta));
   354           srcValue = static_cast<TUint16>( KScale2 * val );
   355 		  *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
   356 		  *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
   357 		 }
   358     
   359 	 aBuffer->Data().SetLength(aSize); 
   360 	}
   361 
   362 /**
   363 *
   364 * PrintComparisonDataL
   365 * Prints out coded results for comparison with the 
   366 * Reference values and is used when the results differ
   367 *
   368 **/
   369 void CMMFPcmU16BtoPcmU16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
   370 	{
   371 	//[precondition reference coded data is equal in size or longer than coded data ]
   372 	if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
   373 		{
   374 		//[coded data is longer than reference data]
   375 	//	RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
   376 		User::Leave( KErrCorrupt );	 
   377 		}
   378 	
   379 	//[ now print the results for comparison ]
   380     TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
   381 	TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
   382     TInt length = aCodedData.Data().Length();
   383 	length /= 2; //[ for 16bit words ]
   384 	TUint16 codedValue = 0;
   385 	TUint16 refCodedValue = 0;
   386 	//[ now print the results for comparison ]
   387 	for( TInt i = 0; i < length; i++ )
   388 		{
   389 		// assemble 16bit values
   390 		AssembleValue( ptr1, codedValue, EFalse);
   391 		AssembleValue( ptr2, refCodedValue, EFalse );        
   392 		RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue );
   393 		if( i % 100 == 0 ) //deal with debug printf deficiencies
   394 			{
   395 			User::After( 100 );
   396 			}
   397 		ptr1+=2;
   398 		ptr2+=2;
   399 		} 	
   400 	}
   401 
   402 /**
   403 *
   404 * CMMFPcm8ToPcm16Generator
   405 *
   406 **/
   407 CMMFPcm8ToPcm16Generator::CMMFPcm8ToPcm16Generator()
   408 	{
   409 	}
   410 
   411 /**
   412 *
   413 * CMMFPcm8ToPcm16Generator
   414 *
   415 **/
   416 CMMFPcm8ToPcm16Generator::~CMMFPcm8ToPcm16Generator()
   417 	{
   418 	}
   419 
   420 /**
   421 *
   422 * GenerateSourceDataL
   423 *
   424 **/
   425 void CMMFPcm8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   426 	{
   427 	const TInt8 KScale2 = 127;
   428 
   429 	 //[ create a buffer large eneough to fill with the data ]
   430 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   431 
   432 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   433 
   434 	//[ lets fill it with a 400hz signal at approx -3db ]
   435 	//[encode the data]
   436 	 TInt8 srcValue = 0;
   437 	 TReal val   = 0.0;
   438 	 TReal theta = 0.0; 
   439      TInt noSamples = aSize/sizeof(TInt8);
   440 	 for(TInt i=0; i< noSamples; i++)
   441 		 {
   442 		 //[ assign data and place in buffer]
   443 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   444 		                      // better reproduction through gsm codec
   445 		  User::LeaveIfError(Math::Sin(val,theta));
   446           srcValue = static_cast<TInt8>( (KScale2 * val) );
   447           *pDst++ = srcValue;
   448 		 }
   449     
   450 	 aBuffer->Data().SetLength(aSize); 
   451 	}
   452 
   453 /**
   454 *
   455 * GenerateSourceDataL
   456 *
   457 **/
   458 void CMMFPcm8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   459 	{
   460 	const TInt8 KScale2 = 127;
   461 
   462 	 //[ create a buffer large eneough to fill with the data ]
   463 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   464 
   465 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   466 
   467 	//[ lets fill it with a 400hz signal at approx -3db ]
   468 	//[encode the data]
   469 	 TInt16 srcValue = 0;
   470 	 TReal val   = 0.0;
   471 	 TReal theta = 0.0; 
   472 	 TInt noSamples = aSize/sizeof(TInt16);
   473 	 for(TInt i=0; i< noSamples; i++)
   474 		 {
   475 		 //[ assign data and place in buffer]
   476 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   477 		                      // better reproduction through gsm codec
   478 		  User::LeaveIfError(Math::Sin(val,theta));
   479 		  TInt8 temp = static_cast<TInt8>((KScale2 * val));
   480           srcValue =  static_cast<TInt16>( temp << 8); 
   481 		  *pDst++ = static_cast<TInt8>( srcValue&KAndMask8bit);
   482 		  *pDst++ = static_cast<TInt8>((srcValue>>8)&KAndMask8bit);
   483 		 }
   484     
   485 	 aBuffer->Data().SetLength(aSize); 
   486 	}
   487 
   488 /**
   489 *
   490 * PrintComparisonDataL
   491 * Prints out coded results for comparison with the 
   492 * Reference values and is used when the results differ
   493 *
   494 **/
   495 void CMMFPcm8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
   496 	{
   497 	//[precondition reference coded data is equal in size or longer than coded data ]
   498 	if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
   499 		{
   500 		//[coded data is longer than reference data]
   501 	//	RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
   502 		User::Leave( KErrCorrupt );	 
   503 		}
   504 	
   505 	//[ now print the results for comparison ]
   506     TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
   507 	TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
   508     TInt length = aCodedData.Data().Length();
   509 	length /= 2; //[ for 16bit words ]
   510 	TInt16 codedValue = 0;
   511 	TInt16 refCodedValue = 0;
   512 	//[ now print the results for comparison ]
   513 	for( TInt i = 0; i < length; i++ )
   514 		{
   515 		// assemble 16bit values
   516   		AssembleValue( ptr1, codedValue, EFalse );
   517 		AssembleValue( ptr2, refCodedValue, EFalse );        
   518 		RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (refCodedValue-codedValue), codedValue, refCodedValue );
   519 		if( i % 100 == 0 ) //deal with debug printf deficiencies
   520 			{
   521 			User::After(100 );
   522 			}
   523 		ptr1+=2;
   524 		ptr2+=2;
   525 		} 	
   526 	}
   527 
   528 /**
   529 *
   530 * CMMFPcmU8ToPcm16Generator
   531 *
   532 **/
   533 CMMFPcmU8ToPcm16Generator::CMMFPcmU8ToPcm16Generator()
   534 	 {
   535 	 }
   536 
   537 /**
   538 *
   539 * ~CMMFPcmU8ToPcm16Generator
   540 *
   541 **/
   542 CMMFPcmU8ToPcm16Generator::~CMMFPcmU8ToPcm16Generator()
   543 	 {
   544 	 }
   545 
   546 /**
   547 *
   548 * GenerateSourceDataL
   549 * @param aBuffer
   550 * @param aSize in bytes
   551 *
   552 **/
   553 void CMMFPcmU8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   554 	 {
   555 	 const TUint8 KScale2 = 127;
   556 
   557 	 //[ create a buffer large eneough to fill with the data ]
   558 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   559 
   560 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   561 
   562 	//[ lets fill it with a 400hz signal at approx -3db ]
   563 	//[encode the data]
   564 	 TUint8 srcValue = 0;
   565 	 TReal val   = 0.0;
   566 	 TReal theta = 0.0; 
   567 	 TInt noSamples = aSize/sizeof(TUint8);
   568 	 for(TInt i=0; i< noSamples; i++)
   569 		 {
   570 		 //[ assign data and place in buffer]
   571 		  theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or
   572 		                      // better reproduction through gsm codec
   573 		  User::LeaveIfError(Math::Sin(val,theta));
   574 
   575           srcValue = static_cast<TUint8>((KScale2 * val+KScale2+0.5));
   576           *pDst++ = srcValue;
   577 		   //RDebug::Print( _L("U8 = %u"), srcValue );  Statement commented under DEf105143
   578 		 }
   579     
   580 	 aBuffer->Data().SetLength(aSize); 
   581 	 }
   582 
   583 /**
   584 *
   585 * GenerateComparisonDataL
   586 * @param aBuffer
   587 * @param aSize
   588 *
   589 **/
   590 void CMMFPcmU8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   591 	{
   592 	const TInt8 KScale2 = 127;
   593 	
   594 	//[ create a buffer large eneough to fill with the data ]
   595 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   596 	
   597 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   598 	
   599 	//[ lets fill it with a 400hz signal at approx -3db ]
   600 	//[encode the data]
   601 //	RDebug::Print( _L("Generation"));Commented under DEF105143
   602 	TUint8 theValue = 0;
   603 	TReal val   = 0.0;
   604 	TReal theta = 0.0; 
   605 	TUint8 rrr  = 0;
   606 	TInt length = aSize/sizeof(TInt16);
   607 	for(TInt i=0; i< length; i++)
   608 		{
   609 		//[ assign data and place in buffer]
   610 		theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or
   611 		// better reproduction through gsm codec
   612 		User::LeaveIfError(Math::Sin(val,theta));
   613 		theValue = static_cast<TUint8>(KScale2 *val + KScale2 + 0.5); 
   614 		//[ apply the same transformation as the codec ]
   615 		rrr = static_cast<TUint8>( theValue^KMaskSign8bit );
   616 		//RDebug::Print( _L("U8 = %u"), theValue ); Statement commented under DEf105143
   617 		*pDst++ = rrr;
   618 		*pDst++ = rrr;
   619 		}
   620     
   621 	aBuffer->Data().SetLength(aSize); 
   622 	}
   623 
   624 /**
   625 *
   626 * PrintComparisonDataL
   627 * Prints out coded results for comparison with the 
   628 * Reference values and is used when the results differ
   629 *
   630 **/
   631 void CMMFPcmU8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
   632 	{
   633 	//[precondition reference coded data is equal in size or longer than coded data ]
   634 	if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
   635 		{
   636 		//[coded data is longer than reference data]
   637 	//	RDebug::Print( _L("Coded Data is longer than reference data"));Commented under DEF105143
   638 		User::Leave( KErrCorrupt );	 
   639 		}
   640 	
   641 	//[ now print the results for comparison ]
   642     TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
   643 	TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
   644     TInt length = aCodedData.Data().Length();
   645 	length /= 2; //[ for 16bit words ]
   646 	TInt16 codedValue = 0;
   647 	TInt16 refCodedValue = 0;
   648 	//[ now print the results for comparison ]
   649 	for( TInt i = 0; i < length; i++ )
   650 		{
   651 		// assemble 16bit values
   652   		AssembleValue( ptr1, codedValue, EFalse );
   653 		AssembleValue( ptr2, refCodedValue, EFalse );        
   654 		RDebug::Print( _L("delta %d c %d, rf %d"), (refCodedValue-codedValue), codedValue, refCodedValue );
   655 		if( i % 100 == 0 ) //deal with debug printf deficiencies
   656 			{
   657 			User::After(100 );
   658 			}
   659 		ptr1+=2;
   660 		ptr2+=2;
   661 		} 
   662 
   663 	}
   664 
   665 /**
   666 *
   667 * CMMFPcm16ToPcmU8Generator
   668 *
   669 **/
   670 CMMFPcm16ToPcmU8Generator::CMMFPcm16ToPcmU8Generator()
   671 	{
   672      //Nothing doing
   673 	}
   674 
   675 /**
   676 *
   677 * CMMFPcm16ToPcmU8Generator
   678 *
   679 **/
   680 CMMFPcm16ToPcmU8Generator::~CMMFPcm16ToPcmU8Generator()
   681 	{
   682      //Nothing doing
   683 	}
   684 
   685 /**
   686 *
   687 * GenerateSourceDataL
   688 * @param aBuffer
   689 * @param aSize in bytes
   690 * This function generates a 400hz sine wav
   691 * under the assumption the sampling frequency is 8khz
   692 *
   693 */
   694 void CMMFPcm16ToPcmU8Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   695 	{
   696 	const TInt KScale = 320;
   697 
   698 	 //[ create a buffer large eneough to fill with the data ]
   699 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   700 
   701 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   702 
   703 	//[ lets fill it with a 400hz signal at approx -3db ]
   704 	//[encode the data]
   705 	 TInt16 srcValue = 0;
   706 	 TReal val   = 0.0;
   707 	 TReal theta = 0.0; 
   708 	 TInt noSamples = aSize/sizeof(TInt16);
   709 	 for(TInt i=0; i< noSamples; i++)
   710 		 {
   711 		 //[ assign data and place in buffer]
   712 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   713 		                      // better reproduction through gsm codec
   714 		  User::LeaveIfError(Math::Sin(val,theta));
   715           srcValue = static_cast<TInt16>( KScale * val );
   716           *pDst++ = static_cast<TUint8>( srcValue & KAndMask8bit);
   717 		  *pDst++ = static_cast<TUint8>((srcValue >> 8) & KAndMask8bit );
   718 		 }
   719     
   720 	 aBuffer->Data().SetLength(aSize); 
   721 	}
   722 
   723 /**
   724 *
   725 * GenerateComparisonDataL
   726 * @param aBuffer
   727 * @param aSize in bytes
   728 * This function generates a 400hz sine wav
   729 * under the assumption the sampling frequency is 8khz
   730 */
   731 //[ use partial sopecialization to provide copncrete implmentation]
   732 void CMMFPcm16ToPcmU8Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
   733 	{
   734 	const TInt KScale2 = 320; //low value chosen to emphasize the distortion of this codec!
   735 
   736 	 //[ create a buffer large eneough to fill with the data ]
   737 	aBuffer = CMMFDescriptorBuffer::NewL(aSize);
   738 
   739 	TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
   740 
   741 	//[ lets fill it with a 400hz signal at approx -3db ]
   742 	//[encode the data]
   743 	 TInt16 srcValue = 0;
   744 	 TReal val   = 0.0;
   745 	 TReal theta = 0.0; 
   746 	 TInt noSamples = aSize/sizeof(TUint8);
   747 	 for(TInt i=0; i< noSamples; i++)
   748 		 {
   749 		 //[ assign data and place in buffer]
   750 		  theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
   751 		                      // better reproduction through gsm codec
   752 		  User::LeaveIfError(Math::Sin(val,theta));
   753           srcValue = static_cast<TInt16>( KScale2 * val );
   754           *pDst++ = static_cast<TUint8>( (srcValue >> 8) - KMaskSign8bit);
   755 		 }
   756     
   757 	 aBuffer->Data().SetLength(aSize); 
   758 	}
   759 
   760 /**
   761 *
   762 * PrintComparisonDataL
   763 * Prints out coded results for comparison with the 
   764 * Reference values and is used when the results differ
   765 *
   766 **/
   767 void CMMFPcm16ToPcmU8Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
   768 	{
   769 	//[precondition reference coded data is equal in size or longer than coded data ]
   770 	if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
   771 		{
   772          //[coded data is longer than reference data]
   773 	//	RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
   774 		User::Leave( KErrCorrupt );	 
   775 		}
   776 
   777 	//[ now print the results for comparison ]
   778     TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
   779 	TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
   780     TInt length = aCodedData.Data().Length();
   781 	//[ now print the results for comparison ]
   782 	for( TInt i = 0; i < length; i++ )
   783 		{
   784 		RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (*ptr1-*ptr2), *ptr1, *ptr2 );
   785 		if( i % 100 == 0 ) //deal with debug printf deficiencies
   786 			{
   787 			User::After(100 );
   788 			}
   789 		ptr1++;
   790 		ptr2++;
   791 		} 
   792 	}
   793 
   794 /**
   795 *
   796 * CompareData
   797 * @param aData1 first data buffer for comparison
   798 * @param aData2 second data buffer for comparison
   799 * result TBool data is the same
   800 * @precondition aData1 has the same amount of data as aData2
   801 *
   802 */
   803 template <class T, class Generator, TInt index>
   804 TBool CTestStepSignConversionTest<T, Generator, index>::CompareData( CMMFDataBuffer* aData1, CMMFDataBuffer* aData2)
   805 	{
   806 	TBool result = ETrue;
   807 
   808 	//[ precondition aData1 != NULL ]
   809 	if( !aData1 )
   810 		{
   811 		User::Leave( KErrArgument );
   812 		}
   813 
   814     //[ precondition aData2 != NULL ]
   815 	if( !aData2 )
   816 		{
   817 		User::Leave( KErrArgument );
   818 		}
   819 
   820     //[precondition aData1 length == aData2 length ]
   821 	if( aData1->Data().Length() != aData2->Data().Length() )
   822 		{
   823 		User::Leave( KErrArgument );
   824 		}
   825 
   826 	//[Now Compare the data]
   827 	TUint8* ptr1 = CONST_CAST(TUint8*, aData1->Data().Ptr());
   828 	TUint8* ptr2 = CONST_CAST(TUint8*, aData2->Data().Ptr());
   829 	TInt dataLength = aData2->Data().Length();
   830    	if( Mem::Compare( ptr1, dataLength, ptr2, dataLength )!=0)
   831 		{
   832 		TUint8* p1 = ptr1; 
   833         TUint8* p2 = ptr2;
   834 		TInt16 s1  = 0;
   835 		TInt16 s2  = 0;
   836 		INFO_PRINTF1(_L("------------------------------"));
   837 		for( TInt i = 0; i < dataLength/2; i++ )
   838 			{
   839 		    s1  = static_cast<TInt16>( p1[0] &KAndMask8bit);  
   840 		    s1 |=  static_cast<TInt16>((p1[1] << 8 ));
   841 		    s2  = static_cast<TInt16>( p2[0] &KAndMask8bit);  
   842 		    s2 |=  static_cast<TInt16>((p2[1] << 8 ));
   843 			INFO_PRINTF3(_L("%d  %d"), s1, s2);
   844 			p1+=2;
   845 			p2+=2;
   846 			}
   847 		INFO_PRINTF1(_L("------------------------------"));
   848 	//	RDebug::Print( _L("Comparison has failed")); Commented under DEF105143
   849 		iGenerator->PrintComparisonDataL( *aData1, *aData2 );
   850 		result = EFalse ;
   851 		}
   852 	return result;
   853 	}
   854 
   855 /**
   856 *
   857 * DoTestStepL
   858 * @result TVerdict
   859 *
   860 */
   861 template <class T, class Generator, TInt index>
   862 TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepL()
   863 	{
   864 	__MM_HEAP_MARK;	
   865 	TVerdict result = EPass;
   866 
   867 	//[pre condition iSourceData ]
   868 	if( !iSourceData )
   869 		{
   870 		INFO_PRINTF1(_L("Source Data Failure"));
   871 		User::Leave( KErrCorrupt);
   872 		}
   873 	//[precondition iCodedData  ]
   874 	if( !iCodedData )
   875 		{
   876 		INFO_PRINTF1(_L("Coded Data Failure"));
   877 		User::Leave( KErrCorrupt);
   878 		}
   879 	//[precondition iRefData ]
   880 	if( !iRefCodedData )
   881 		{
   882 		INFO_PRINTF1(_L("RefCodedData Argument Failure"));
   883 		User::Leave( KErrCorrupt);
   884 		}
   885 
   886 	//[ lets code the data and compare it to the reference data ]
   887     iCodecUnderTest->ProcessL(*iSourceData, *iCodedData);
   888     if(!CompareData(iCodedData, iRefCodedData))
   889 		{
   890 		INFO_PRINTF1(_L("Coded Results do not match reference coded results"));
   891 
   892 		result = EFail;
   893 		}
   894 	
   895 	__MM_HEAP_MARKEND;
   896 	return result;
   897 	}
   898 
   899 /**
   900 *
   901 * DoTestStepPostambleL
   902 * @result TVerdict
   903 *
   904 */
   905 template <class T, class Generator, TInt index>
   906 TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepPostambleL()
   907 	{
   908 	TVerdict result = EPass;	
   909 	//[delete the buffers & Codec]
   910 	delete iCodecUnderTest;
   911 	delete iGenerator;
   912 	delete iSourceData;
   913 	delete iCodedData;
   914 	delete iRefCodedData;
   915 	return result;
   916 	}
   917 
   918 /**
   919 *
   920 * DoTestStepPreambleL
   921 * @result TVerdict
   922 *
   923 */
   924 template <class T, class Generator, TInt index>
   925 TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepPreambleL()
   926 	{
   927 	TVerdict result = EPass;
   928 
   929 	iCodecUnderTest =  new(ELeave) T;   // a cmmfcodec ;
   930 	iGenerator = new(ELeave) Generator; // src generator
   931 
   932   	//[ensure the number of samples is >= srcbuffers]
   933 	const TInt KNumBuffers = 2;
   934 	const TInt dataSrcSize = KNumBuffers *  iCodecUnderTest->SourceBufferSize();
   935 
   936 	//[generate src data]
   937 	iGenerator->GenerateSourceDataL( iSourceData, dataSrcSize);
   938 	
   939 	const TInt dataSinkSize = KNumBuffers *  iCodecUnderTest->SinkBufferSize();
   940 
   941 	//[generate comparison data]
   942 	iGenerator->GenerateComparisonDataL( iRefCodedData, dataSinkSize);
   943 
   944 	//[reserve space for coded data ]
   945     iCodedData = CMMFDescriptorBuffer::NewL(dataSinkSize);
   946 
   947 	return result;
   948 	}
   949 
   950 /**
   951 *
   952 * CTestStepCodecUnitTest
   953 *
   954 */
   955 template <class T, class Generator, TInt index>
   956 CTestStepSignConversionTest<T, Generator, index>::CTestStepSignConversionTest()
   957 	{
   958 	// store the name of this test case
   959 	// this is the name that is used by the script file
   960 	iTestStepName = (&KSignConversionParameters[index])->iTestName;
   961 	}
   962 
   963 /**
   964 *
   965 * CTestStepCodecUnitTest
   966 *
   967 */
   968 template <class T, class Generator, TInt index>
   969 CTestStepSignConversionTest<T, Generator, index>::~CTestStepSignConversionTest()
   970 	{
   971 	}
   972 
   973 /**
   974 *
   975 * This is used for template instantiation.
   976 *
   977 **/
   978 
   979 template class CTestStepSignConversionTest<CMMFPcm16ToPcmU8Codec,CMMFPcm16ToPcmU8Generator,0>;
   980 template class CTestStepSignConversionTest<CMMFPcm8ToPcm16Codec,CMMFPcm8ToPcm16Generator,1>;
   981 template class CTestStepSignConversionTest<CMMFPcm16SwapEndianCodec,CMMFPcmU16toPcmU16BGenerator,2>;
   982 template class CTestStepSignConversionTest<CMMFPcm16SwapEndianCodec,CMMFPcmU16BtoPcmU16Generator,3>;
   983 template class CTestStepSignConversionTest<CMMFPcmU8ToPcm16Codec,CMMFPcmU8ToPcm16Generator,4>;
   984