os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_SignConversionCodecs.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_SignConversionCodecs.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,984 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// TSU_MMF_CodecTests.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +// EPOC includes
1.22 +#include <e32base.h>
1.23 +#include <e32math.h>
1.24 +#include <f32file.h>
1.25 +#include <s32file.h>
1.26 +
1.27 +// Test system includes
1.28 +#include "TSU_MMF_DeviceSuite.h"
1.29 +#include "TSU_MMF_SignConversionCodecs.h"
1.30 +
1.31 +//[ codec includes ]
1.32 +#include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
1.33 +#include "MmfPcm16toAlawhwDevice.h"
1.34 +#include "MmfALawToPcm16HwDevice.h"
1.35 +#include "mmfpcm16toMulawhwdevice.h"
1.36 +#include "MmfMuLawToPcm16hwDevice.h"
1.37 +#include "mmfpcmS8ToPcmS16HwDevice.h"
1.38 +#include "mmfpcmS16PcmS8HwDevice.h"
1.39 +#include "mmfpcm16topcmU16BEHwDevice.h"
1.40 +#include "mmfpcm16SwapEndianhwdevice.h"
1.41 +#include "mmfpcm16ToImaAdpcm.h"
1.42 +#include "MmfImaAdpcmtopcm16hwdevice.h"
1.43 +#include "MMFpcm16ToPcm16HwDevice.h"
1.44 +#include "MMFpcm16ToPcmU8HwDevice.h"
1.45 +#include "MMFpcmU8ToPcm16HwDevice.h"
1.46 +#include "mmfpcmS16PcmS8HwDevice.h"
1.47 +
1.48 +
1.49 +//[ Codec Unit tests structure
1.50 +// The unit tests shall use text files
1.51 +// for small portions of test data
1.52 +// which should be stored are stored in a simple format
1.53 +// containing the relevant parameters for the test
1.54 +//]
1.55 +class TSignConversionTestParams
1.56 + {
1.57 +public:
1.58 + const TText* iTestName; // name of the test
1.59 + };
1.60 +
1.61 +// constant table of parameters for tests
1.62 +const TSignConversionTestParams KSignConversionParameters[] =
1.63 + {
1.64 + {_S("MM-MMF-SWCODECDEVICES-U-0017-HP")},
1.65 + {_S("MM-MMF-SWCODECDEVICES-U-0018-HP")},
1.66 + {_S("MM-MMF-SWCODECDEVICES-U-0019-HP")},
1.67 + {_S("MM-MMF-SWCODECDEVICES-U-0020-HP")},
1.68 + {_S("MM-MMF-SWCODECDEVICES-U-0021-HP")}
1.69 + };
1.70 +
1.71 +/**
1.72 +*
1.73 +* PrintComparisonDataL
1.74 +* @param aCodedData the coded data buffer
1.75 +* @param aRefCodedData the reference coded data buffer
1.76 +*
1.77 +*/
1.78 +void CMMFDataGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
1.79 + {
1.80 + //[precondition reference coded data is equal in size or longer than coded data ]
1.81 + if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
1.82 + {
1.83 + //[coded data is longer than reference data]
1.84 + // RDebug::Print(_L("Coded Data is longer than refernce data")); Commented under DEF105143
1.85 + User::Leave( KErrCorrupt );
1.86 + }
1.87 +
1.88 + TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
1.89 + TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
1.90 + TInt length = aCodedData.Data().Length();
1.91 + //[ now print the results for comparison ]
1.92 + for( TInt i = 0; i < length; i++ )
1.93 + {
1.94 + RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (*ptr1-*ptr2), *ptr1++, *ptr2++ );
1.95 + }
1.96 + }
1.97 +
1.98 +/**
1.99 +*
1.100 +* AssembleValue
1.101 +* @param aData src data buffer
1.102 +* @param aValue resultant value
1.103 +* @param aBigEndian whether the value is in BigEndian format
1.104 +* @precondition aData is not null and has length >= 2
1.105 +*
1.106 +*/
1.107 +void CMMFDataGenerator::AssembleValue( TUint8* aData, TInt16& aValue, TBool aBigEndian )
1.108 + {
1.109 + __ASSERT_DEBUG( aData, Panic(EBadArgument));
1.110 + if( aBigEndian )
1.111 + {
1.112 + aValue = static_cast<TInt16>( aData[1] &KAndMask8bit );
1.113 + aValue |= static_cast<TInt16>((aData[0] << 8 ));
1.114 + }
1.115 + else
1.116 + {
1.117 + aValue = static_cast<TInt16>( aData[0] &KAndMask8bit);
1.118 + aValue |= static_cast<TInt16>((aData[1] << 8 ));
1.119 + }
1.120 + }
1.121 +
1.122 +/**
1.123 +*
1.124 +* AssembleValue
1.125 +* @param aData src data buffer
1.126 +* @param aValue resultant value
1.127 +* @param aBigEndian whether the value is in BigEndian format
1.128 +* @precondition aData is not null and has length >= 2
1.129 +*
1.130 +*/
1.131 +void CMMFDataGenerator::AssembleValue( TUint8* aData, TUint16& aValue, TBool aBigEndian )
1.132 + {
1.133 + __ASSERT_DEBUG( aData, Panic(EBadArgument));
1.134 + if( aBigEndian )
1.135 + {
1.136 + aValue = aData[1] ; //[ big endian format]
1.137 + aValue |= (aData[0] << 8 );
1.138 + }
1.139 + else
1.140 + {
1.141 + aValue = aData[0] ;
1.142 + aValue |= (aData[1] << 8 );
1.143 + }
1.144 + }
1.145 +/**
1.146 +*
1.147 +* CMMFPcmU16toPcmU16BGenerator
1.148 +*
1.149 +**/
1.150 +CMMFPcmU16toPcmU16BGenerator::CMMFPcmU16toPcmU16BGenerator()
1.151 + {
1.152 + }
1.153 +
1.154 +/**
1.155 +*
1.156 +* ~CMMFPcmU16toPcmU16BGenerator
1.157 +*
1.158 +**/
1.159 +CMMFPcmU16toPcmU16BGenerator::~CMMFPcmU16toPcmU16BGenerator()
1.160 + {
1.161 + }
1.162 +
1.163 +/**
1.164 +*
1.165 +* GenerateSourceDataL
1.166 +*
1.167 +**/
1.168 +void CMMFPcmU16toPcmU16BGenerator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.169 + {
1.170 + const TUint16 KScale2 = 32000;
1.171 +
1.172 + //[ create a buffer large enough to fill with the data ]
1.173 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.174 +
1.175 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.176 +
1.177 + //[ lets fill it with a 400hz signal at approx -3db ]
1.178 + //[encode the data]
1.179 + TUint16 srcValue = 0;
1.180 + TReal val = 0.0;
1.181 + TReal theta = 0.0;
1.182 +
1.183 + TInt noSamples = aSize/sizeof(TInt16);
1.184 + for(TInt i=0; i< noSamples; i++)
1.185 + {
1.186 + //[ assign data and place in buffer]
1.187 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.188 + // better reproduction through gsm codec
1.189 + User::LeaveIfError(Math::Sin(val,theta));
1.190 + srcValue = static_cast<TUint16>( (KScale2 * val ) + KScale2+0.5);
1.191 + *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
1.192 + *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
1.193 + }
1.194 +
1.195 + aBuffer->Data().SetLength(aSize);
1.196 + }
1.197 +
1.198 +/**
1.199 +*
1.200 +* GenerateComparisonDataL
1.201 +*
1.202 +**/
1.203 +void CMMFPcmU16toPcmU16BGenerator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.204 + {
1.205 + const TUint16 KScale2 = 32000;
1.206 +
1.207 + //[ create a buffer large eneough to fill with the data ]
1.208 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.209 +
1.210 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.211 +
1.212 + //[ lets fill it with a 400hz signal at approx -3db ]
1.213 + //[encode the data]
1.214 + TUint16 srcValue = 0;
1.215 + TReal val = 0.0;
1.216 + TReal theta = 0.0;
1.217 +
1.218 + TInt noSamples = aSize/sizeof(TInt16);
1.219 + for(TInt i=0; i< noSamples; i++)
1.220 + {
1.221 + //[ assign data and place in buffer]
1.222 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.223 + // better reproduction through gsm codec
1.224 + User::LeaveIfError(Math::Sin(val,theta));
1.225 + srcValue = static_cast<TUint16>( (KScale2 * val)+KScale2 +0.5);
1.226 + //[endian swap here ]
1.227 + *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
1.228 + *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
1.229 + }
1.230 +
1.231 + aBuffer->Data().SetLength(aSize);
1.232 + }
1.233 +
1.234 +/**
1.235 +*
1.236 +* PrintComparisonDataL
1.237 +* Prints out coded results for comparison with the
1.238 +* Reference values and is used when the results differ
1.239 +*
1.240 +**/
1.241 +void CMMFPcmU16toPcmU16BGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
1.242 + {
1.243 + //[precondition reference coded data is equal in size or longer than coded data ]
1.244 + if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
1.245 + {
1.246 + //[coded data is longer than reference data]
1.247 + // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
1.248 + User::Leave( KErrCorrupt );
1.249 + }
1.250 +
1.251 + //[ now print the results for comparison ]
1.252 + TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
1.253 + TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
1.254 + TInt length = aCodedData.Data().Length();
1.255 + length /= 2; // [for 16bit words length is half]
1.256 + //[ assert invariant length is even ]
1.257 + __ASSERT_DEBUG( (length % 2 == 0 ), Panic(EBadInvariant));
1.258 +
1.259 + TUint16 codedValue = 0;
1.260 + TUint16 refCodedValue = 0;
1.261 + //[ now print the results for comparison ]
1.262 + for( TInt i = 0; i < length; i++ )
1.263 + {
1.264 + //[ assemble 16bit values from buffer values ]
1.265 + AssembleValue( ptr1, codedValue, ETrue );
1.266 + AssembleValue( ptr2, refCodedValue, ETrue );
1.267 + RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue );
1.268 + if( i % 100 == 0 ) //deal with debug printf deficiencies
1.269 + {
1.270 + User::After(100 );
1.271 + }
1.272 + ptr1+=2;
1.273 + ptr2+=2;
1.274 + }
1.275 + }
1.276 +
1.277 +/**
1.278 +*
1.279 +* CMMFPcmU16BtoPcmU16Generator
1.280 +*
1.281 +**/
1.282 +CMMFPcmU16BtoPcmU16Generator::CMMFPcmU16BtoPcmU16Generator()
1.283 + {
1.284 + }
1.285 +
1.286 +/**
1.287 +*
1.288 +* ~CMMFPcmU16BtoPcmU16Generator
1.289 +*
1.290 +**/
1.291 +CMMFPcmU16BtoPcmU16Generator::~CMMFPcmU16BtoPcmU16Generator()
1.292 + {
1.293 + }
1.294 +
1.295 +/**
1.296 +*
1.297 +* GenerateSourceDataL
1.298 +*
1.299 +**/
1.300 +void CMMFPcmU16BtoPcmU16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.301 + {
1.302 + const TUint8 KScale2 = 127;
1.303 +
1.304 + //[ create a buffer large eneough to fill with the data ]
1.305 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.306 +
1.307 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.308 +
1.309 + //[ lets fill it with a 400hz signal at approx -3db ]
1.310 + //[encode the data]
1.311 + TInt8 srcValue = 0;
1.312 + TReal val = 0.0;
1.313 + TReal theta = 0.0;
1.314 +
1.315 + TInt noSamples = aSize/sizeof(TInt16);
1.316 + for(TInt i=0; i< noSamples; i++)
1.317 + {
1.318 + //[ assign data and place in buffer]
1.319 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.320 + // better reproduction through gsm codec
1.321 + User::LeaveIfError(Math::Sin(val,theta));
1.322 + srcValue = static_cast<TUint8>( (KScale2 * val) );
1.323 + //[endian swap here ]
1.324 + *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
1.325 + *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
1.326 + }
1.327 +
1.328 + aBuffer->Data().SetLength(aSize);
1.329 + }
1.330 +
1.331 +/**
1.332 +*
1.333 +* GenerateComparisonDataL
1.334 +*
1.335 +**/
1.336 +void CMMFPcmU16BtoPcmU16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.337 + {
1.338 + const TUint8 KScale2 = 127;
1.339 +
1.340 + //[ create a buffer large eneough to fill with the data ]
1.341 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.342 +
1.343 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.344 +
1.345 + //[ lets fill it with a 400hz signal at approx -3db ]
1.346 + //[encode the data]
1.347 + TUint16 srcValue = 0;
1.348 + TReal val = 0.0;
1.349 + TReal theta = 0.0;
1.350 + TInt noSamples = aSize/sizeof(TInt16);
1.351 + for(TInt i=0; i< noSamples; i++)
1.352 + {
1.353 + //[ assign data and place in buffer]
1.354 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.355 + // better reproduction through gsm codec
1.356 + User::LeaveIfError(Math::Sin(val,theta));
1.357 + srcValue = static_cast<TUint16>( KScale2 * val );
1.358 + *pDst++ = static_cast<TUint8>( srcValue &KAndMask8bit);
1.359 + *pDst++ = static_cast<TUint8>( (srcValue >>8) &KAndMask8bit);
1.360 + }
1.361 +
1.362 + aBuffer->Data().SetLength(aSize);
1.363 + }
1.364 +
1.365 +/**
1.366 +*
1.367 +* PrintComparisonDataL
1.368 +* Prints out coded results for comparison with the
1.369 +* Reference values and is used when the results differ
1.370 +*
1.371 +**/
1.372 +void CMMFPcmU16BtoPcmU16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
1.373 + {
1.374 + //[precondition reference coded data is equal in size or longer than coded data ]
1.375 + if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
1.376 + {
1.377 + //[coded data is longer than reference data]
1.378 + // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
1.379 + User::Leave( KErrCorrupt );
1.380 + }
1.381 +
1.382 + //[ now print the results for comparison ]
1.383 + TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
1.384 + TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
1.385 + TInt length = aCodedData.Data().Length();
1.386 + length /= 2; //[ for 16bit words ]
1.387 + TUint16 codedValue = 0;
1.388 + TUint16 refCodedValue = 0;
1.389 + //[ now print the results for comparison ]
1.390 + for( TInt i = 0; i < length; i++ )
1.391 + {
1.392 + // assemble 16bit values
1.393 + AssembleValue( ptr1, codedValue, EFalse);
1.394 + AssembleValue( ptr2, refCodedValue, EFalse );
1.395 + RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue );
1.396 + if( i % 100 == 0 ) //deal with debug printf deficiencies
1.397 + {
1.398 + User::After( 100 );
1.399 + }
1.400 + ptr1+=2;
1.401 + ptr2+=2;
1.402 + }
1.403 + }
1.404 +
1.405 +/**
1.406 +*
1.407 +* CMMFPcm8ToPcm16Generator
1.408 +*
1.409 +**/
1.410 +CMMFPcm8ToPcm16Generator::CMMFPcm8ToPcm16Generator()
1.411 + {
1.412 + }
1.413 +
1.414 +/**
1.415 +*
1.416 +* CMMFPcm8ToPcm16Generator
1.417 +*
1.418 +**/
1.419 +CMMFPcm8ToPcm16Generator::~CMMFPcm8ToPcm16Generator()
1.420 + {
1.421 + }
1.422 +
1.423 +/**
1.424 +*
1.425 +* GenerateSourceDataL
1.426 +*
1.427 +**/
1.428 +void CMMFPcm8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.429 + {
1.430 + const TInt8 KScale2 = 127;
1.431 +
1.432 + //[ create a buffer large eneough to fill with the data ]
1.433 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.434 +
1.435 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.436 +
1.437 + //[ lets fill it with a 400hz signal at approx -3db ]
1.438 + //[encode the data]
1.439 + TInt8 srcValue = 0;
1.440 + TReal val = 0.0;
1.441 + TReal theta = 0.0;
1.442 + TInt noSamples = aSize/sizeof(TInt8);
1.443 + for(TInt i=0; i< noSamples; i++)
1.444 + {
1.445 + //[ assign data and place in buffer]
1.446 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.447 + // better reproduction through gsm codec
1.448 + User::LeaveIfError(Math::Sin(val,theta));
1.449 + srcValue = static_cast<TInt8>( (KScale2 * val) );
1.450 + *pDst++ = srcValue;
1.451 + }
1.452 +
1.453 + aBuffer->Data().SetLength(aSize);
1.454 + }
1.455 +
1.456 +/**
1.457 +*
1.458 +* GenerateSourceDataL
1.459 +*
1.460 +**/
1.461 +void CMMFPcm8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.462 + {
1.463 + const TInt8 KScale2 = 127;
1.464 +
1.465 + //[ create a buffer large eneough to fill with the data ]
1.466 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.467 +
1.468 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.469 +
1.470 + //[ lets fill it with a 400hz signal at approx -3db ]
1.471 + //[encode the data]
1.472 + TInt16 srcValue = 0;
1.473 + TReal val = 0.0;
1.474 + TReal theta = 0.0;
1.475 + TInt noSamples = aSize/sizeof(TInt16);
1.476 + for(TInt i=0; i< noSamples; i++)
1.477 + {
1.478 + //[ assign data and place in buffer]
1.479 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.480 + // better reproduction through gsm codec
1.481 + User::LeaveIfError(Math::Sin(val,theta));
1.482 + TInt8 temp = static_cast<TInt8>((KScale2 * val));
1.483 + srcValue = static_cast<TInt16>( temp << 8);
1.484 + *pDst++ = static_cast<TInt8>( srcValue&KAndMask8bit);
1.485 + *pDst++ = static_cast<TInt8>((srcValue>>8)&KAndMask8bit);
1.486 + }
1.487 +
1.488 + aBuffer->Data().SetLength(aSize);
1.489 + }
1.490 +
1.491 +/**
1.492 +*
1.493 +* PrintComparisonDataL
1.494 +* Prints out coded results for comparison with the
1.495 +* Reference values and is used when the results differ
1.496 +*
1.497 +**/
1.498 +void CMMFPcm8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
1.499 + {
1.500 + //[precondition reference coded data is equal in size or longer than coded data ]
1.501 + if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
1.502 + {
1.503 + //[coded data is longer than reference data]
1.504 + // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
1.505 + User::Leave( KErrCorrupt );
1.506 + }
1.507 +
1.508 + //[ now print the results for comparison ]
1.509 + TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
1.510 + TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
1.511 + TInt length = aCodedData.Data().Length();
1.512 + length /= 2; //[ for 16bit words ]
1.513 + TInt16 codedValue = 0;
1.514 + TInt16 refCodedValue = 0;
1.515 + //[ now print the results for comparison ]
1.516 + for( TInt i = 0; i < length; i++ )
1.517 + {
1.518 + // assemble 16bit values
1.519 + AssembleValue( ptr1, codedValue, EFalse );
1.520 + AssembleValue( ptr2, refCodedValue, EFalse );
1.521 + RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (refCodedValue-codedValue), codedValue, refCodedValue );
1.522 + if( i % 100 == 0 ) //deal with debug printf deficiencies
1.523 + {
1.524 + User::After(100 );
1.525 + }
1.526 + ptr1+=2;
1.527 + ptr2+=2;
1.528 + }
1.529 + }
1.530 +
1.531 +/**
1.532 +*
1.533 +* CMMFPcmU8ToPcm16Generator
1.534 +*
1.535 +**/
1.536 +CMMFPcmU8ToPcm16Generator::CMMFPcmU8ToPcm16Generator()
1.537 + {
1.538 + }
1.539 +
1.540 +/**
1.541 +*
1.542 +* ~CMMFPcmU8ToPcm16Generator
1.543 +*
1.544 +**/
1.545 +CMMFPcmU8ToPcm16Generator::~CMMFPcmU8ToPcm16Generator()
1.546 + {
1.547 + }
1.548 +
1.549 +/**
1.550 +*
1.551 +* GenerateSourceDataL
1.552 +* @param aBuffer
1.553 +* @param aSize in bytes
1.554 +*
1.555 +**/
1.556 +void CMMFPcmU8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.557 + {
1.558 + const TUint8 KScale2 = 127;
1.559 +
1.560 + //[ create a buffer large eneough to fill with the data ]
1.561 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.562 +
1.563 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.564 +
1.565 + //[ lets fill it with a 400hz signal at approx -3db ]
1.566 + //[encode the data]
1.567 + TUint8 srcValue = 0;
1.568 + TReal val = 0.0;
1.569 + TReal theta = 0.0;
1.570 + TInt noSamples = aSize/sizeof(TUint8);
1.571 + for(TInt i=0; i< noSamples; i++)
1.572 + {
1.573 + //[ assign data and place in buffer]
1.574 + theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or
1.575 + // better reproduction through gsm codec
1.576 + User::LeaveIfError(Math::Sin(val,theta));
1.577 +
1.578 + srcValue = static_cast<TUint8>((KScale2 * val+KScale2+0.5));
1.579 + *pDst++ = srcValue;
1.580 + //RDebug::Print( _L("U8 = %u"), srcValue ); Statement commented under DEf105143
1.581 + }
1.582 +
1.583 + aBuffer->Data().SetLength(aSize);
1.584 + }
1.585 +
1.586 +/**
1.587 +*
1.588 +* GenerateComparisonDataL
1.589 +* @param aBuffer
1.590 +* @param aSize
1.591 +*
1.592 +**/
1.593 +void CMMFPcmU8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.594 + {
1.595 + const TInt8 KScale2 = 127;
1.596 +
1.597 + //[ create a buffer large eneough to fill with the data ]
1.598 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.599 +
1.600 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.601 +
1.602 + //[ lets fill it with a 400hz signal at approx -3db ]
1.603 + //[encode the data]
1.604 +// RDebug::Print( _L("Generation"));Commented under DEF105143
1.605 + TUint8 theValue = 0;
1.606 + TReal val = 0.0;
1.607 + TReal theta = 0.0;
1.608 + TUint8 rrr = 0;
1.609 + TInt length = aSize/sizeof(TInt16);
1.610 + for(TInt i=0; i< length; i++)
1.611 + {
1.612 + //[ assign data and place in buffer]
1.613 + theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or
1.614 + // better reproduction through gsm codec
1.615 + User::LeaveIfError(Math::Sin(val,theta));
1.616 + theValue = static_cast<TUint8>(KScale2 *val + KScale2 + 0.5);
1.617 + //[ apply the same transformation as the codec ]
1.618 + rrr = static_cast<TUint8>( theValue^KMaskSign8bit );
1.619 + //RDebug::Print( _L("U8 = %u"), theValue ); Statement commented under DEf105143
1.620 + *pDst++ = rrr;
1.621 + *pDst++ = rrr;
1.622 + }
1.623 +
1.624 + aBuffer->Data().SetLength(aSize);
1.625 + }
1.626 +
1.627 +/**
1.628 +*
1.629 +* PrintComparisonDataL
1.630 +* Prints out coded results for comparison with the
1.631 +* Reference values and is used when the results differ
1.632 +*
1.633 +**/
1.634 +void CMMFPcmU8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
1.635 + {
1.636 + //[precondition reference coded data is equal in size or longer than coded data ]
1.637 + if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
1.638 + {
1.639 + //[coded data is longer than reference data]
1.640 + // RDebug::Print( _L("Coded Data is longer than reference data"));Commented under DEF105143
1.641 + User::Leave( KErrCorrupt );
1.642 + }
1.643 +
1.644 + //[ now print the results for comparison ]
1.645 + TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
1.646 + TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
1.647 + TInt length = aCodedData.Data().Length();
1.648 + length /= 2; //[ for 16bit words ]
1.649 + TInt16 codedValue = 0;
1.650 + TInt16 refCodedValue = 0;
1.651 + //[ now print the results for comparison ]
1.652 + for( TInt i = 0; i < length; i++ )
1.653 + {
1.654 + // assemble 16bit values
1.655 + AssembleValue( ptr1, codedValue, EFalse );
1.656 + AssembleValue( ptr2, refCodedValue, EFalse );
1.657 + RDebug::Print( _L("delta %d c %d, rf %d"), (refCodedValue-codedValue), codedValue, refCodedValue );
1.658 + if( i % 100 == 0 ) //deal with debug printf deficiencies
1.659 + {
1.660 + User::After(100 );
1.661 + }
1.662 + ptr1+=2;
1.663 + ptr2+=2;
1.664 + }
1.665 +
1.666 + }
1.667 +
1.668 +/**
1.669 +*
1.670 +* CMMFPcm16ToPcmU8Generator
1.671 +*
1.672 +**/
1.673 +CMMFPcm16ToPcmU8Generator::CMMFPcm16ToPcmU8Generator()
1.674 + {
1.675 + //Nothing doing
1.676 + }
1.677 +
1.678 +/**
1.679 +*
1.680 +* CMMFPcm16ToPcmU8Generator
1.681 +*
1.682 +**/
1.683 +CMMFPcm16ToPcmU8Generator::~CMMFPcm16ToPcmU8Generator()
1.684 + {
1.685 + //Nothing doing
1.686 + }
1.687 +
1.688 +/**
1.689 +*
1.690 +* GenerateSourceDataL
1.691 +* @param aBuffer
1.692 +* @param aSize in bytes
1.693 +* This function generates a 400hz sine wav
1.694 +* under the assumption the sampling frequency is 8khz
1.695 +*
1.696 +*/
1.697 +void CMMFPcm16ToPcmU8Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.698 + {
1.699 + const TInt KScale = 320;
1.700 +
1.701 + //[ create a buffer large eneough to fill with the data ]
1.702 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.703 +
1.704 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.705 +
1.706 + //[ lets fill it with a 400hz signal at approx -3db ]
1.707 + //[encode the data]
1.708 + TInt16 srcValue = 0;
1.709 + TReal val = 0.0;
1.710 + TReal theta = 0.0;
1.711 + TInt noSamples = aSize/sizeof(TInt16);
1.712 + for(TInt i=0; i< noSamples; i++)
1.713 + {
1.714 + //[ assign data and place in buffer]
1.715 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.716 + // better reproduction through gsm codec
1.717 + User::LeaveIfError(Math::Sin(val,theta));
1.718 + srcValue = static_cast<TInt16>( KScale * val );
1.719 + *pDst++ = static_cast<TUint8>( srcValue & KAndMask8bit);
1.720 + *pDst++ = static_cast<TUint8>((srcValue >> 8) & KAndMask8bit );
1.721 + }
1.722 +
1.723 + aBuffer->Data().SetLength(aSize);
1.724 + }
1.725 +
1.726 +/**
1.727 +*
1.728 +* GenerateComparisonDataL
1.729 +* @param aBuffer
1.730 +* @param aSize in bytes
1.731 +* This function generates a 400hz sine wav
1.732 +* under the assumption the sampling frequency is 8khz
1.733 +*/
1.734 +//[ use partial sopecialization to provide copncrete implmentation]
1.735 +void CMMFPcm16ToPcmU8Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize )
1.736 + {
1.737 + const TInt KScale2 = 320; //low value chosen to emphasize the distortion of this codec!
1.738 +
1.739 + //[ create a buffer large eneough to fill with the data ]
1.740 + aBuffer = CMMFDescriptorBuffer::NewL(aSize);
1.741 +
1.742 + TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr());
1.743 +
1.744 + //[ lets fill it with a 400hz signal at approx -3db ]
1.745 + //[encode the data]
1.746 + TInt16 srcValue = 0;
1.747 + TReal val = 0.0;
1.748 + TReal theta = 0.0;
1.749 + TInt noSamples = aSize/sizeof(TUint8);
1.750 + for(TInt i=0; i< noSamples; i++)
1.751 + {
1.752 + //[ assign data and place in buffer]
1.753 + theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or
1.754 + // better reproduction through gsm codec
1.755 + User::LeaveIfError(Math::Sin(val,theta));
1.756 + srcValue = static_cast<TInt16>( KScale2 * val );
1.757 + *pDst++ = static_cast<TUint8>( (srcValue >> 8) - KMaskSign8bit);
1.758 + }
1.759 +
1.760 + aBuffer->Data().SetLength(aSize);
1.761 + }
1.762 +
1.763 +/**
1.764 +*
1.765 +* PrintComparisonDataL
1.766 +* Prints out coded results for comparison with the
1.767 +* Reference values and is used when the results differ
1.768 +*
1.769 +**/
1.770 +void CMMFPcm16ToPcmU8Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData )
1.771 + {
1.772 + //[precondition reference coded data is equal in size or longer than coded data ]
1.773 + if( aRefCodedData.Data().Length() < aCodedData.Data().Length() )
1.774 + {
1.775 + //[coded data is longer than reference data]
1.776 + // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143
1.777 + User::Leave( KErrCorrupt );
1.778 + }
1.779 +
1.780 + //[ now print the results for comparison ]
1.781 + TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr());
1.782 + TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr());
1.783 + TInt length = aCodedData.Data().Length();
1.784 + //[ now print the results for comparison ]
1.785 + for( TInt i = 0; i < length; i++ )
1.786 + {
1.787 + RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (*ptr1-*ptr2), *ptr1, *ptr2 );
1.788 + if( i % 100 == 0 ) //deal with debug printf deficiencies
1.789 + {
1.790 + User::After(100 );
1.791 + }
1.792 + ptr1++;
1.793 + ptr2++;
1.794 + }
1.795 + }
1.796 +
1.797 +/**
1.798 +*
1.799 +* CompareData
1.800 +* @param aData1 first data buffer for comparison
1.801 +* @param aData2 second data buffer for comparison
1.802 +* result TBool data is the same
1.803 +* @precondition aData1 has the same amount of data as aData2
1.804 +*
1.805 +*/
1.806 +template <class T, class Generator, TInt index>
1.807 +TBool CTestStepSignConversionTest<T, Generator, index>::CompareData( CMMFDataBuffer* aData1, CMMFDataBuffer* aData2)
1.808 + {
1.809 + TBool result = ETrue;
1.810 +
1.811 + //[ precondition aData1 != NULL ]
1.812 + if( !aData1 )
1.813 + {
1.814 + User::Leave( KErrArgument );
1.815 + }
1.816 +
1.817 + //[ precondition aData2 != NULL ]
1.818 + if( !aData2 )
1.819 + {
1.820 + User::Leave( KErrArgument );
1.821 + }
1.822 +
1.823 + //[precondition aData1 length == aData2 length ]
1.824 + if( aData1->Data().Length() != aData2->Data().Length() )
1.825 + {
1.826 + User::Leave( KErrArgument );
1.827 + }
1.828 +
1.829 + //[Now Compare the data]
1.830 + TUint8* ptr1 = CONST_CAST(TUint8*, aData1->Data().Ptr());
1.831 + TUint8* ptr2 = CONST_CAST(TUint8*, aData2->Data().Ptr());
1.832 + TInt dataLength = aData2->Data().Length();
1.833 + if( Mem::Compare( ptr1, dataLength, ptr2, dataLength )!=0)
1.834 + {
1.835 + TUint8* p1 = ptr1;
1.836 + TUint8* p2 = ptr2;
1.837 + TInt16 s1 = 0;
1.838 + TInt16 s2 = 0;
1.839 + INFO_PRINTF1(_L("------------------------------"));
1.840 + for( TInt i = 0; i < dataLength/2; i++ )
1.841 + {
1.842 + s1 = static_cast<TInt16>( p1[0] &KAndMask8bit);
1.843 + s1 |= static_cast<TInt16>((p1[1] << 8 ));
1.844 + s2 = static_cast<TInt16>( p2[0] &KAndMask8bit);
1.845 + s2 |= static_cast<TInt16>((p2[1] << 8 ));
1.846 + INFO_PRINTF3(_L("%d %d"), s1, s2);
1.847 + p1+=2;
1.848 + p2+=2;
1.849 + }
1.850 + INFO_PRINTF1(_L("------------------------------"));
1.851 + // RDebug::Print( _L("Comparison has failed")); Commented under DEF105143
1.852 + iGenerator->PrintComparisonDataL( *aData1, *aData2 );
1.853 + result = EFalse ;
1.854 + }
1.855 + return result;
1.856 + }
1.857 +
1.858 +/**
1.859 +*
1.860 +* DoTestStepL
1.861 +* @result TVerdict
1.862 +*
1.863 +*/
1.864 +template <class T, class Generator, TInt index>
1.865 +TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepL()
1.866 + {
1.867 + __MM_HEAP_MARK;
1.868 + TVerdict result = EPass;
1.869 +
1.870 + //[pre condition iSourceData ]
1.871 + if( !iSourceData )
1.872 + {
1.873 + INFO_PRINTF1(_L("Source Data Failure"));
1.874 + User::Leave( KErrCorrupt);
1.875 + }
1.876 + //[precondition iCodedData ]
1.877 + if( !iCodedData )
1.878 + {
1.879 + INFO_PRINTF1(_L("Coded Data Failure"));
1.880 + User::Leave( KErrCorrupt);
1.881 + }
1.882 + //[precondition iRefData ]
1.883 + if( !iRefCodedData )
1.884 + {
1.885 + INFO_PRINTF1(_L("RefCodedData Argument Failure"));
1.886 + User::Leave( KErrCorrupt);
1.887 + }
1.888 +
1.889 + //[ lets code the data and compare it to the reference data ]
1.890 + iCodecUnderTest->ProcessL(*iSourceData, *iCodedData);
1.891 + if(!CompareData(iCodedData, iRefCodedData))
1.892 + {
1.893 + INFO_PRINTF1(_L("Coded Results do not match reference coded results"));
1.894 +
1.895 + result = EFail;
1.896 + }
1.897 +
1.898 + __MM_HEAP_MARKEND;
1.899 + return result;
1.900 + }
1.901 +
1.902 +/**
1.903 +*
1.904 +* DoTestStepPostambleL
1.905 +* @result TVerdict
1.906 +*
1.907 +*/
1.908 +template <class T, class Generator, TInt index>
1.909 +TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepPostambleL()
1.910 + {
1.911 + TVerdict result = EPass;
1.912 + //[delete the buffers & Codec]
1.913 + delete iCodecUnderTest;
1.914 + delete iGenerator;
1.915 + delete iSourceData;
1.916 + delete iCodedData;
1.917 + delete iRefCodedData;
1.918 + return result;
1.919 + }
1.920 +
1.921 +/**
1.922 +*
1.923 +* DoTestStepPreambleL
1.924 +* @result TVerdict
1.925 +*
1.926 +*/
1.927 +template <class T, class Generator, TInt index>
1.928 +TVerdict CTestStepSignConversionTest<T, Generator, index>::DoTestStepPreambleL()
1.929 + {
1.930 + TVerdict result = EPass;
1.931 +
1.932 + iCodecUnderTest = new(ELeave) T; // a cmmfcodec ;
1.933 + iGenerator = new(ELeave) Generator; // src generator
1.934 +
1.935 + //[ensure the number of samples is >= srcbuffers]
1.936 + const TInt KNumBuffers = 2;
1.937 + const TInt dataSrcSize = KNumBuffers * iCodecUnderTest->SourceBufferSize();
1.938 +
1.939 + //[generate src data]
1.940 + iGenerator->GenerateSourceDataL( iSourceData, dataSrcSize);
1.941 +
1.942 + const TInt dataSinkSize = KNumBuffers * iCodecUnderTest->SinkBufferSize();
1.943 +
1.944 + //[generate comparison data]
1.945 + iGenerator->GenerateComparisonDataL( iRefCodedData, dataSinkSize);
1.946 +
1.947 + //[reserve space for coded data ]
1.948 + iCodedData = CMMFDescriptorBuffer::NewL(dataSinkSize);
1.949 +
1.950 + return result;
1.951 + }
1.952 +
1.953 +/**
1.954 +*
1.955 +* CTestStepCodecUnitTest
1.956 +*
1.957 +*/
1.958 +template <class T, class Generator, TInt index>
1.959 +CTestStepSignConversionTest<T, Generator, index>::CTestStepSignConversionTest()
1.960 + {
1.961 + // store the name of this test case
1.962 + // this is the name that is used by the script file
1.963 + iTestStepName = (&KSignConversionParameters[index])->iTestName;
1.964 + }
1.965 +
1.966 +/**
1.967 +*
1.968 +* CTestStepCodecUnitTest
1.969 +*
1.970 +*/
1.971 +template <class T, class Generator, TInt index>
1.972 +CTestStepSignConversionTest<T, Generator, index>::~CTestStepSignConversionTest()
1.973 + {
1.974 + }
1.975 +
1.976 +/**
1.977 +*
1.978 +* This is used for template instantiation.
1.979 +*
1.980 +**/
1.981 +
1.982 +template class CTestStepSignConversionTest<CMMFPcm16ToPcmU8Codec,CMMFPcm16ToPcmU8Generator,0>;
1.983 +template class CTestStepSignConversionTest<CMMFPcm8ToPcm16Codec,CMMFPcm8ToPcm16Generator,1>;
1.984 +template class CTestStepSignConversionTest<CMMFPcm16SwapEndianCodec,CMMFPcmU16toPcmU16BGenerator,2>;
1.985 +template class CTestStepSignConversionTest<CMMFPcm16SwapEndianCodec,CMMFPcmU16BtoPcmU16Generator,3>;
1.986 +template class CTestStepSignConversionTest<CMMFPcmU8ToPcm16Codec,CMMFPcmU8ToPcm16Generator,4>;
1.987 +