1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/SwCodecDevices/TSU_MMF_SWCODECDEVICES.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2145 @@
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 +//
1.18 +
1.19 +// EPOC includes
1.20 +#include <e32base.h>
1.21 +#include <e32math.h>
1.22 +#include "types.h"
1.23 +#include "gsm610fr.h"
1.24 +#include "MMFAudioCodecBase.h"
1.25 +
1.26 +// Test system includes
1.27 +#include "TSU_MMF_SWCODECDEVICES.h"
1.28 +#include "TSU_MMF_SwCodecDevices_BufferSizes.h"
1.29 +#include "TSU_MMF_DeviceSuite.h"
1.30 +#include "MMFAudioSPcm16ToALawCodec.h"
1.31 +#include "MMFAudioALawToS16PcmCodec.h"
1.32 +#include "MMFAudioMuLawToS16PcmCodec.h"
1.33 +#include "MMFAudioSPcm16ToMuLawCodec.h"
1.34 +#include "mmfpcm16ToImaAdpcm.h"
1.35 +#include "MmfImaAdpcmtopcm16hwdevice.h"
1.36 +#include "GSM610.H"
1.37 +
1.38 +/**
1.39 +*
1.40 +* CTestStep_MMF_SwCodecDevices
1.41 +*
1.42 +**/
1.43 +CTestStep_MMF_SwCodecDevices::CTestStep_MMF_SwCodecDevices()
1.44 + {
1.45 + iHeapSize = 300000;
1.46 + }
1.47 +
1.48 +/**
1.49 +*
1.50 +* ~CTestStep_MMF_SwCodecDevices
1.51 +*
1.52 +*/
1.53 +CTestStep_MMF_SwCodecDevices::~CTestStep_MMF_SwCodecDevices()
1.54 + {
1.55 + }
1.56 +
1.57 +/**
1.58 +*
1.59 +* SetSuite
1.60 +* @param aPtr ref to the test suite
1.61 +*
1.62 +**/
1.63 +void CTestStep_MMF_SwCodecDevices::SetSuite( CTestSuite_MMF_SwCodecDevices* aPtr )
1.64 + {
1.65 + iRefSuite = aPtr;
1.66 + }
1.67 +/**
1.68 +*
1.69 +* GetSuite
1.70 +* @return CTestSuite_MMF_SwCodecDevices*
1.71 +*
1.72 +**/
1.73 +CTestSuite_MMF_SwCodecDevices* CTestStep_MMF_SwCodecDevices::GetSuite()
1.74 + {
1.75 + return iRefSuite;
1.76 + }
1.77 +/**
1.78 +*
1.79 +* CTest_MMF_Gsm610
1.80 +*
1.81 +*/
1.82 +CTest_MMF_Gsm610::CTest_MMF_Gsm610()
1.83 + {
1.84 +
1.85 + }
1.86 +
1.87 +/**
1.88 +*
1.89 +* CTest_MMF_SwCodecDevices_U_0001
1.90 +*
1.91 +*/
1.92 +CTest_MMF_SwCodecDevices_U_0001::CTest_MMF_SwCodecDevices_U_0001()
1.93 + {
1.94 + // store the name of this test case
1.95 + // this is the name that is used by the script file
1.96 + iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0001-HP");
1.97 + }
1.98 +
1.99 +/**
1.100 +*
1.101 +* CTest_MMF_SwCodecDevices_U_0001
1.102 +*
1.103 +**/
1.104 +CTest_MMF_SwCodecDevices_U_0001::~CTest_MMF_SwCodecDevices_U_0001()
1.105 + {
1.106 +
1.107 + }
1.108 +/**
1.109 +*
1.110 +*
1.111 +* ~CTest_MMF_Gsm610
1.112 +*
1.113 +*/
1.114 +CTest_MMF_Gsm610::~CTest_MMF_Gsm610()
1.115 + {
1.116 + // nothing to do ..
1.117 + }
1.118 +
1.119 +/**
1.120 +*
1.121 +*
1.122 +* DoTestStepL
1.123 +*
1.124 +*/
1.125 +TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepL()
1.126 + {
1.127 + __MM_HEAP_MARK;
1.128 + TVerdict result = EPass ;
1.129 +
1.130 + CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
1.131 + CleanupStack::PushL(pDecoder);
1.132 +
1.133 + // do the same for the inverse operation
1.134 + CMmfPcm16ToGsm610HwDevice* pEncoder = CMmfPcm16ToGsm610HwDevice::NewL();
1.135 + CleanupStack::PushL(pEncoder);
1.136 + CMMFSwCodec& theEncode = pEncoder->Codec();
1.137 +
1.138 + //[ create buffers of the appropriate size ]
1.139 + const TInt srcBufferSize = theEncode.SourceBufferSize();
1.140 + const TInt sinkBufferSize = theEncode.SinkBufferSize();
1.141 + const TInt codedBufferSize = 76*4* KNumFramesInABuffer; // number of coded buffers * size of coded buffer 63*2
1.142 + iNumCodedFrames = KNumFramesInABuffer; //XXX claculate these constants soon <GK>
1.143 +
1.144 + iScratchData = CMMFDescriptorBuffer::NewL( codedBufferSize);
1.145 +
1.146 + //[ pcm data buffers ]
1.147 + iRefSrcData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.148 + iDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.149 +
1.150 + //[ coded data buffers ]
1.151 + iRefCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.152 + iRefDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.153 + iCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.154 +
1.155 + //[ for now process only the first few buffers
1.156 + // and encode the data]
1.157 + INFO_PRINTF1(_L("Encoding Frame..."));
1.158 + TInt srcFileSize = 0;
1.159 + iSrcFile.Size( srcFileSize);
1.160 + TInt buffLen =iRefSrcData->Data().MaxLength();
1.161 + TInt numBuffers = srcFileSize/buffLen;
1.162 + if( numBuffers > 4 ) // [ not all buffers are processed without error
1.163 + // and this is the intention probably of the test sequences]
1.164 + numBuffers = 4;
1.165 + TInt badBufferCount = 0;
1.166 + TInt goodBufferCount = 0;
1.167 +
1.168 + for( TInt bufferCount = 0; bufferCount < numBuffers; bufferCount++ )
1.169 + {
1.170 + //[precondition pointers are ok]
1.171 + ReadDataBufferL(iSrcFile, *iRefSrcData );
1.172 +
1.173 + ParseCodedDataL(iRefCodedData);
1.174 +
1.175 + CMMFSwCodec::TCodecProcessResult encodeRes = theEncode.ProcessL( *iRefSrcData, *iCodedData );
1.176 + if( encodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
1.177 + {
1.178 + INFO_PRINTF1( _L("Error Failed to complete coding") );
1.179 + return EFail;
1.180 + }
1.181 +
1.182 + //[ compare results ]
1.183 + if( !CompareEncodeResults( iCodedData, iRefCodedData ) )
1.184 + {
1.185 + result = EFail;
1.186 + badBufferCount++;
1.187 + }
1.188 + else
1.189 + {
1.190 + goodBufferCount++;
1.191 + }
1.192 +
1.193 + }
1.194 +
1.195 + //[ log number of good buffers & number of bad buffers ]
1.196 + INFO_PRINTF4(_L("Good Buffers %d, Bad Buffers %d, Total Buffers %d"),
1.197 + goodBufferCount, badBufferCount, badBufferCount+goodBufferCount );
1.198 +
1.199 + //[pop data from the cleanup stack ]
1.200 + CleanupStack::PopAndDestroy(2, pDecoder); //pDecoder, theCodec
1.201 +
1.202 + delete iRefSrcData; // reference source data
1.203 + iRefSrcData = NULL;
1.204 + delete iRefCodedData; //reference coded data
1.205 + iRefCodedData = NULL;
1.206 + delete iRefDecodedData; // reference decoded data
1.207 + iRefDecodedData = NULL;
1.208 + delete iCodedData; // buffer of coded data
1.209 + iCodedData = NULL;
1.210 + delete iDecodedData; // buffer of actual decoded data
1.211 + iDecodedData = NULL;
1.212 + delete iScratchData; // scratch data buffer
1.213 + iScratchData = NULL;
1.214 +
1.215 + __MM_HEAP_MARKEND;
1.216 +
1.217 + return result;
1.218 + }
1.219 +
1.220 +/**
1.221 +*
1.222 +* ParseCodedDataL
1.223 +*
1.224 +*/
1.225 +void CTest_MMF_Gsm610::ParseCodedDataL( CMMFDataBuffer* aBuffer )
1.226 + {
1.227 + codes frame0;
1.228 + codes frame1;
1.229 +
1.230 + //[ read all the coded data into the scratch buffer from reference file ]
1.231 + ReadDataBufferL( iCodedFile, *iScratchData );
1.232 + TUint8* dest = const_cast<TUint8*>(aBuffer->Data().Ptr());
1.233 + TUint8* src = const_cast<TUint8*>(iScratchData->Data().Ptr());
1.234 +
1.235 + //[ for all the coded frames parse these frames to proper coded form ]
1.236 + for( TInt count = 0; count < iNumCodedFrames; count++ )
1.237 + {
1.238 + // parse data to frame
1.239 + ParseFrameL( frame0, src );
1.240 + ParseFrameL( frame1, src );
1.241 + //[ finally pack the two frames into the coded data buffer ]
1.242 + PackFrame0( &frame0, reinterpret_cast<TInt8*>(dest) );
1.243 + PackFrame1( &frame1, reinterpret_cast<TInt8*>(dest) );
1.244 + dest+= KGsmFrameSize;
1.245 + }
1.246 +
1.247 + aBuffer->Data().SetLength(KGsmFrameSize*iNumCodedFrames);
1.248 + }
1.249 +/**
1.250 +*
1.251 +* ParseFrame
1.252 +* @param aFrame this stores the gsm frame in an unpacked structure
1.253 +* @param aBuffer this contains the reference file data as 76 words
1.254 +*
1.255 +*/
1.256 +void CTest_MMF_Gsm610::ParseFrameL( struct codes& aFrame, TUint8* &aSrc )
1.257 + {
1.258 + for(TInt i = 0; i < 8; i++ )
1.259 + {
1.260 + aFrame.LARc[i] = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
1.261 + aFrame.LARc[i] |= static_cast<TInt16>(*aSrc++ << 8 );
1.262 + }
1.263 +
1.264 + for( TInt j = 0; j < 4; j++ )
1.265 + {
1.266 + aFrame.sfc[j].Nc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
1.267 + aFrame.sfc[j].Nc |= static_cast<TInt16>(*aSrc++ << 8 );
1.268 + aFrame.sfc[j].bc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
1.269 + aFrame.sfc[j].bc |= static_cast<TInt16>(*aSrc++ << 8 );
1.270 + aFrame.sfc[j].Mc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
1.271 + aFrame.sfc[j].Mc |= static_cast<TInt16>(*aSrc++ << 8 );
1.272 + aFrame.sfc[j].xmaxc = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
1.273 + aFrame.sfc[j].xmaxc |= static_cast<TInt16>(*aSrc++ << 8 );
1.274 +
1.275 + for( TInt k = 0; k < 13; k++ )
1.276 + {
1.277 + aFrame.sfc[j].xMc[k] = static_cast<TInt16> (*aSrc++ &KAndMask8bit );
1.278 + aFrame.sfc[j].xMc[k] |= static_cast<TInt16>(*aSrc++ << 8 );
1.279 + }
1.280 +
1.281 + }
1.282 +
1.283 + }
1.284 +
1.285 +/**
1.286 +*
1.287 +* DoTestStepPreambleL
1.288 +*
1.289 +*/
1.290 +enum TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepPreambleL(void)
1.291 + {
1.292 + TVerdict result = EPass;
1.293 + //[ connect to the file server ]
1.294 + User::LeaveIfError( iFs.Connect());
1.295 +
1.296 + //[ read the ref source data ]
1.297 + if(!GetStringFromConfig(_L("SectionOne"), _L("SourceData01"), iSourceDataFile) ||
1.298 + !GetStringFromConfig(_L("SectionOne"), _L("CodedData01"), iCodedDataFile) ||
1.299 + !GetStringFromConfig(_L("SectionOne"), _L("DecodedData01"), iDecodedDataFile) )
1.300 + {
1.301 + return EInconclusive;
1.302 + }
1.303 +
1.304 + //[ open the data files]
1.305 + OpenFileL(iSrcFile,iSourceDataFile );
1.306 + OpenFileL(iCodedFile,iCodedDataFile );
1.307 + OpenFileL(iDecodeFile,iDecodedDataFile);
1.308 + return result;
1.309 + }
1.310 +
1.311 +/**
1.312 +*
1.313 +* CompareCodedResults
1.314 +* @param aEncodedFrame
1.315 +* @param aRefFrame
1.316 +* @result TBool
1.317 +*
1.318 +*/
1.319 +TBool CTest_MMF_Gsm610::CompareEncodeResults( CMMFDataBuffer* aEncoded, CMMFDataBuffer* aRefFrame )
1.320 + {
1.321 + TBool result = ETrue;
1.322 +
1.323 + //[precondition no encoded frames == refframes ]
1.324 + __ASSERT_DEBUG(aEncoded,Panic(EBadArgument));
1.325 + __ASSERT_DEBUG(aRefFrame,Panic(EBadArgument));
1.326 +
1.327 + TInt upperLimit = aEncoded->Data().Length()/KGsmFrameSize;
1.328 +
1.329 + const CMMFDataBuffer* encoded = STATIC_CAST(const CMMFDataBuffer*, aEncoded);
1.330 + const CMMFDataBuffer* reference = STATIC_CAST(CMMFDataBuffer*, aRefFrame);
1.331 +
1.332 + TUint8* pFrames = CONST_CAST(TUint8*,encoded->Data().Ptr());
1.333 + TUint8* pRefFrames = CONST_CAST(TUint8*,reference->Data().Ptr());
1.334 +
1.335 + TInt badFrameCount = 0;
1.336 + TInt goodFrameCount = 0;
1.337 +
1.338 + //[ for all frames ]
1.339 + for( TInt index = 0; index < upperLimit; index++ )
1.340 + {
1.341 + //[ compare src and ref frame]
1.342 + if( !CompareGsm610Frames( pFrames, pRefFrames ))
1.343 + {
1.344 + result = EFalse;
1.345 + badFrameCount++;
1.346 + INFO_PRINTF2(_L("Bad Frame Number: %d"), index );
1.347 + }
1.348 + else{
1.349 + goodFrameCount++;
1.350 + }
1.351 +
1.352 + //[ increment frame pointers by size of gsmencoded frame
1.353 + pFrames += KGsmFrameSize;
1.354 + pRefFrames += KGsmFrameSize;
1.355 + }
1.356 +
1.357 + //[ log number of good frames & number of bad frames ]
1.358 + INFO_PRINTF4(_L("Good Frames %d, Bad Frames %d, Total Frames %d"),
1.359 + goodFrameCount, badFrameCount, badFrameCount+goodFrameCount );
1.360 +
1.361 + return result ;
1.362 + }
1.363 +
1.364 +/**
1.365 +*
1.366 +* CompareGsm610Frames
1.367 +* This function compares two encoded gsm610 frames
1.368 +* @result TBool Frames are the same or different
1.369 +*
1.370 +**/
1.371 +TBool CTest_MMF_Gsm610::CompareGsm610Frames( TUint8* aGsmFrame,TUint8* aRefGsmFrame )
1.372 + {
1.373 + TBool result = ETrue;
1.374 + ASSERT( aGsmFrame );
1.375 + __ASSERT_DEBUG(aGsmFrame,Panic(EBadArgument));
1.376 + __ASSERT_DEBUG(aRefGsmFrame,Panic(EBadArgument));
1.377 +
1.378 + codes codeBuf0;
1.379 + codes codeBuf1;
1.380 + codes refCodeBuf0;
1.381 + codes refCodeBuf1;
1.382 +
1.383 + UnpackFrame0(&codeBuf0, aGsmFrame );
1.384 + UnpackFrame1(&codeBuf1, aGsmFrame );
1.385 + UnpackFrame0(&refCodeBuf0, aRefGsmFrame );
1.386 + UnpackFrame1(&refCodeBuf1, aRefGsmFrame );
1.387 +
1.388 + if( !Compare( codeBuf0, refCodeBuf0 ) ||
1.389 + !Compare( codeBuf1, refCodeBuf1) )
1.390 +
1.391 + {
1.392 + //LogGsmFrames( codeBuf0, refCodeBuf0 ); // add for debug reasons
1.393 + //LogGsmFrames( codeBuf1, refCodeBuf1 ); // add for debugging reasons
1.394 + result = EFalse;
1.395 + }
1.396 +
1.397 + return result ;
1.398 + }
1.399 +
1.400 +/**
1.401 +*
1.402 +* LogGsmFrames
1.403 +* @param aGsmFrame
1.404 +* @param aRefGsmFrame
1.405 +*
1.406 +**/
1.407 +void CTest_MMF_Gsm610::LogGsmFrames( codes& aGsmFrame, codes& aRefGsmFrame )
1.408 + {
1.409 + //[ print the quantized lar coefficients ]
1.410 + INFO_PRINTF1(_L("Coded Frame:"));
1.411 + LogGsmFrame( aGsmFrame );
1.412 + INFO_PRINTF1(_L("Reference Frame:"));
1.413 + LogGsmFrame( aRefGsmFrame );
1.414 + }
1.415 +
1.416 +/**
1.417 +*
1.418 +* LogGsmFrame
1.419 +* prints a GsmFrame to the test log
1.420 +* @param aFrame
1.421 +*
1.422 +**/
1.423 +void CTest_MMF_Gsm610::LogGsmFrame ( codes& aFrame )
1.424 + {
1.425 + INFO_PRINTF2(_L("LARc[0] = %d"), aFrame.LARc[0]);
1.426 + INFO_PRINTF2(_L("LARc[1] = %d"), aFrame.LARc[1]);
1.427 + INFO_PRINTF2(_L("LARc[2] = %d"), aFrame.LARc[2]);
1.428 + INFO_PRINTF2(_L("LARc[3] = %d"), aFrame.LARc[3]);
1.429 + INFO_PRINTF2(_L("LARc[4] = %d"), aFrame.LARc[4]);
1.430 + INFO_PRINTF2(_L("LARc[5] = %d"), aFrame.LARc[5]);
1.431 + INFO_PRINTF2(_L("LARc[6] = %d"), aFrame.LARc[6]);
1.432 + INFO_PRINTF2(_L("LARc[7] = %d"), aFrame.LARc[7]);
1.433 +
1.434 + //[ for each sub frame print its data ]
1.435 + for( TInt i = 0; i < 4; i++ )
1.436 + {
1.437 + INFO_PRINTF2(_L("Nc = %d"), aFrame.sfc[i].Nc);
1.438 + INFO_PRINTF2(_L("bc = %d"), aFrame.sfc[i].bc);
1.439 + INFO_PRINTF2(_L("Mc= %d"), aFrame.sfc[i].Mc);
1.440 + INFO_PRINTF2(_L("xmaxc = %d"), aFrame.sfc[i].xmaxc);
1.441 + INFO_PRINTF2(_L("xMc[0] = %d"), aFrame.sfc[i].xMc[0]);
1.442 + INFO_PRINTF2(_L("xMc[1] = %d"), aFrame.sfc[i].xMc[1]);
1.443 + INFO_PRINTF2(_L("xMc[2] = %d"), aFrame.sfc[i].xMc[2]);
1.444 + INFO_PRINTF2(_L("xMc[3] = %d"), aFrame.sfc[i].xMc[3]);
1.445 + INFO_PRINTF2(_L("xMc[4] = %d"), aFrame.sfc[i].xMc[4]);
1.446 + INFO_PRINTF2(_L("xMc[5] = %d"), aFrame.sfc[i].xMc[5]);
1.447 + INFO_PRINTF2(_L("xMc[6] = %d"), aFrame.sfc[i].xMc[6]);
1.448 + INFO_PRINTF2(_L("xMc[7] = %d"), aFrame.sfc[i].xMc[7]);
1.449 + INFO_PRINTF2(_L("xMc[8] = %d"), aFrame.sfc[i].xMc[8]);
1.450 + INFO_PRINTF2(_L("xMc[9] = %d"), aFrame.sfc[i].xMc[9]);
1.451 + INFO_PRINTF2(_L("xMc[10] = %d"), aFrame.sfc[i].xMc[10]);
1.452 + INFO_PRINTF2(_L("xMc[11] = %d"), aFrame.sfc[i].xMc[11]);
1.453 + INFO_PRINTF2(_L("xMc[12] = %d"), aFrame.sfc[i].xMc[12]);
1.454 + }
1.455 + }
1.456 +
1.457 +/**
1.458 +*
1.459 +* Compare
1.460 +*
1.461 +**/
1.462 +TBool CTest_MMF_Gsm610::Compare( codes& aFrame1, codes& aFrame2 )
1.463 + {
1.464 + TBool result = ETrue;
1.465 +
1.466 + if( (aFrame1.LARc[0] != aFrame2.LARc[0] ) ||
1.467 + (aFrame1.LARc[1] != aFrame2.LARc[1] ) ||
1.468 + (aFrame1.LARc[2] != aFrame2.LARc[2] ) ||
1.469 + (aFrame1.LARc[3] != aFrame2.LARc[3] ) ||
1.470 + (aFrame1.LARc[4] != aFrame2.LARc[4] ) ||
1.471 + (aFrame1.LARc[5] != aFrame2.LARc[5] ) ||
1.472 + (aFrame1.LARc[6] != aFrame2.LARc[6] ) ||
1.473 + (aFrame1.LARc[7] != aFrame2.LARc[7] ) )
1.474 + {
1.475 + result = EFalse;
1.476 + }
1.477 +
1.478 + for( TInt i = 0; i < 4; i++ )
1.479 + {
1.480 + if(
1.481 + (aFrame1.sfc[i].Nc != aFrame2.sfc[i].Nc) ||
1.482 + (aFrame1.sfc[i].bc != aFrame2.sfc[i].bc) ||
1.483 + (aFrame1.sfc[i].Mc != aFrame2.sfc[i].Mc) ||
1.484 + (aFrame1.sfc[i].xmaxc != aFrame2.sfc[i].xmaxc) ||
1.485 + (aFrame1.sfc[i].xMc[0] != aFrame2.sfc[i].xMc[0]) ||
1.486 + (aFrame1.sfc[i].xMc[1] != aFrame2.sfc[i].xMc[1]) ||
1.487 + (aFrame1.sfc[i].xMc[2] != aFrame2.sfc[i].xMc[2]) ||
1.488 + (aFrame1.sfc[i].xMc[3] != aFrame2.sfc[i].xMc[3]) ||
1.489 + (aFrame1.sfc[i].xMc[4] != aFrame2.sfc[i].xMc[4]) ||
1.490 + (aFrame1.sfc[i].xMc[5] != aFrame2.sfc[i].xMc[5]) ||
1.491 + (aFrame1.sfc[i].xMc[6] != aFrame2.sfc[i].xMc[6]) ||
1.492 + (aFrame1.sfc[i].xMc[7] != aFrame2.sfc[i].xMc[7]) ||
1.493 + (aFrame1.sfc[i].xMc[8] != aFrame2.sfc[i].xMc[8]) ||
1.494 + (aFrame1.sfc[i].xMc[9] != aFrame2.sfc[i].xMc[9]) ||
1.495 + (aFrame1.sfc[i].xMc[10] != aFrame2.sfc[i].xMc[10]) ||
1.496 + (aFrame1.sfc[i].xMc[11] != aFrame2.sfc[i].xMc[11]) ||
1.497 + (aFrame1.sfc[i].xMc[12] != aFrame2.sfc[i].xMc[12]))
1.498 + {
1.499 + result = EFail;
1.500 + }
1.501 + }
1.502 +
1.503 + return result;
1.504 + }
1.505 +
1.506 +/**
1.507 +*
1.508 +* CompareCodedResults
1.509 +*
1.510 +*/
1.511 +TBool CTest_MMF_Gsm610::CompareDecodeResults(CMMFDataBuffer* aEncoded, CMMFDataBuffer* aRefFrame )
1.512 + {
1.513 + TBool result = ETrue;
1.514 +
1.515 + //[ precondition the buffers are of the same length ]
1.516 + __ASSERT_DEBUG(aEncoded,Panic(EBadArgument));
1.517 + __ASSERT_DEBUG(aRefFrame,Panic(EBadArgument));
1.518 + __ASSERT_DEBUG(aEncoded->Data().MaxLength() == aRefFrame->Data().MaxLength(),Panic(EBadArgument));
1.519 +
1.520 + TUint8 *pResults = CONST_CAST(TUint8*,aEncoded->Data().Ptr());
1.521 + TUint8 *pRefData = CONST_CAST(TUint8*,aRefFrame->Data().Ptr());
1.522 + TInt numResults = aEncoded->Data().MaxLength();
1.523 +
1.524 + if (Mem::Compare( pResults,numResults,pRefData,numResults)!=0)
1.525 + {
1.526 + result = EFalse;
1.527 + }
1.528 +
1.529 + return result ;
1.530 + }
1.531 +/**
1.532 +*
1.533 +* ReadDataL
1.534 +* Reads entire data file into buffer
1.535 +*
1.536 +**/
1.537 +void CTest_MMF_Gsm610::ReadDataL( CMMFDataBuffer*& aBuffer, const TDesC& aFile1 )
1.538 + {
1.539 + TFileName fileName = GetSuite()->DefaultPath();
1.540 + fileName.Append(aFile1);
1.541 +
1.542 + RFile file1;
1.543 + User::LeaveIfError(file1.Open(iFs, fileName, EFileShareAny | EFileStream | EFileRead));
1.544 + CleanupClosePushL(file1);
1.545 + TInt fileSize = 0;
1.546 + User::LeaveIfError(file1.Size(fileSize));
1.547 + aBuffer = CMMFDescriptorBuffer::NewL(fileSize);
1.548 + User::LeaveIfError(file1.Read( aBuffer->Data(),fileSize));
1.549 + CleanupStack::PopAndDestroy(1); //file1
1.550 + }
1.551 +
1.552 +/**
1.553 +*
1.554 +* OpenFileL
1.555 +* @param aFile
1.556 +* @param aFileName
1.557 +*
1.558 +**/
1.559 +void CTest_MMF_Gsm610::OpenFileL( RFile& aFile, const TDesC& aFileName )
1.560 + {
1.561 + User::LeaveIfError(aFile.Open(iFs, aFileName, EFileShareAny | EFileStream | EFileRead));
1.562 + }
1.563 +
1.564 +/**
1.565 +*
1.566 +* CloseFileL
1.567 +* @param aFile
1.568 +*
1.569 +**/
1.570 +void CTest_MMF_Gsm610::CloseFileL( RFile& aFile )
1.571 + {
1.572 + aFile.Close();
1.573 + }
1.574 +
1.575 +/**
1.576 +*
1.577 +* ReadDataBuffer
1.578 +* @param aFile
1.579 +* assumes file reads sufficient data
1.580 +*
1.581 +**/
1.582 +void CTest_MMF_Gsm610::ReadDataBufferL( const RFile& aFile, CMMFDataBuffer& aBuffer )
1.583 + {
1.584 + //[ The read will set the length of the descriptor to the number of bytes read]
1.585 + User::LeaveIfError(aFile.Read( aBuffer.Data(),aBuffer.Data().MaxLength() ));
1.586 + INFO_PRINTF2(_L("Bytes read = %d"), aBuffer.Data().Length() );
1.587 + }
1.588 +
1.589 +/**
1.590 +*
1.591 +* FillPcmBuffer
1.592 +* @param aSrcBuffer
1.593 +* Fill a buffer with a sine wave
1.594 +*
1.595 +**/
1.596 +void CTest_MMF_Gsm610::FillPcmBuffer( CMMFDataBuffer& aSrcBuffer )
1.597 + {
1.598 + //fill the Src Buffer
1.599 + TUint8* pDst = CONST_CAST(TUint8*,aSrcBuffer.Data().Ptr());
1.600 + TInt length = aSrcBuffer.Data().MaxLength();
1.601 +
1.602 + //[encode the data]
1.603 + TInt16 srcValue = 0;
1.604 + TReal val = 0.0;
1.605 + TReal theta = 0.0;
1.606 + for(TInt i=0; i<length/2; i++)
1.607 + {
1.608 + //[ assign data and place in buffer]
1.609 + theta = KPi*i/5; // fundamental of 800hz sampled @8khz has 20 db or
1.610 + // better reproduction through gsm codec
1.611 + User::LeaveIfError(Math::Sin(val,theta));
1.612 + srcValue = static_cast<TInt16>( 1000 * val );
1.613 + *pDst++ = static_cast<TUint8>( srcValue & KAndMask8bit);
1.614 + *pDst++ = static_cast<TUint8>((srcValue >> 8) & KAndMask8bit );
1.615 + //INFO_PRINTF2(_L("Sine = %d"), srcValue ); //uncomment for debugging purposes
1.616 + }
1.617 +
1.618 + aSrcBuffer.Data().SetLength(length);
1.619 +
1.620 + }
1.621 +
1.622 +/**
1.623 +*
1.624 +* DoTestStepPostambleL
1.625 +* @result TVerdict
1.626 +*
1.627 +*/
1.628 +TVerdict CTest_MMF_SwCodecDevices_U_0001::DoTestStepPostambleL(void)
1.629 + {
1.630 + // close files
1.631 + CloseFileL( iSrcFile );
1.632 + CloseFileL( iCodedFile );
1.633 + CloseFileL( iDecodeFile );
1.634 + //[ clean up the buffers etc ]
1.635 + delete iRefSrcData; // reference source data
1.636 + delete iRefCodedData; //reference coded data
1.637 + delete iRefDecodedData; // reference decoded data
1.638 + delete iCodedData; // buffer of coded data
1.639 + delete iDecodedData; // buffer of actual decoded data
1.640 + delete iScratchData; // scratch data buffer
1.641 + return EPass;
1.642 + }
1.643 +
1.644 +/**
1.645 +*
1.646 +* UnpackFrame0
1.647 +* @param aCodeBuf
1.648 +* @param pbuf
1.649 +*
1.650 +**/
1.651 +void CTest_MMF_Gsm610::UnpackFrame0(codes* aCodeBuf, TUint8* pbuf)
1.652 + {
1.653 + TInt16* LAR = aCodeBuf->LARc;
1.654 +
1.655 + // unpack the LAR[0..7] from the first 4.5 bytes
1.656 + LAR[0] = (TInt16)((pbuf[0] & 0x3F));
1.657 + LAR[1] = (TInt16)(((pbuf[0] & 0xC0) >> 6) | ((pbuf[1] & 0x0F) << 2));
1.658 + LAR[2] = (TInt16)(((pbuf[1] & 0xF0) >> 4) | ((pbuf[2] & 0x01) << 4));
1.659 + LAR[3] = (TInt16)(((pbuf[2] & 0x3E) >> 1));
1.660 + LAR[4] = (TInt16)(((pbuf[2] & 0xC0) >> 6) | ((pbuf[3] & 0x03) << 2));
1.661 + LAR[5] = (TInt16)(((pbuf[3] & 0x3C) >> 2));
1.662 + LAR[6] = (TInt16)(((pbuf[3] & 0xC0) >> 6) | ((pbuf[4] & 0x01) << 2));
1.663 + LAR[7] = (TInt16)(((pbuf[4] & 0x0E) >> 1));
1.664 +
1.665 + // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
1.666 + for(TInt i = 0; i < 4; i++)
1.667 + {
1.668 + struct sfcodes& c = aCodeBuf->sfc[i];
1.669 +#define sfb(x) (pbuf[4+i*7+x])
1.670 + c.Nc = (TInt16)(((sfb(0) & 0xF0) >> 4) | ((sfb(1) & 0x07) << 4));
1.671 + c.bc = (TInt16)(((sfb(1) & 0x18) >> 3));
1.672 + c.Mc = (TInt16)(((sfb(1) & 0x60) >> 5));
1.673 + c.xmaxc = (TInt16)(((sfb(1) & 0x80) >> 7) | ((sfb(2) & 0x1F) << 1));
1.674 + c.xMc[0] = (TInt16)(((sfb(2) & 0xE0) >> 5));
1.675 + c.xMc[1] = (TInt16)((sfb(3) & 0x07));
1.676 + c.xMc[2] = (TInt16)(((sfb(3) & 0x3C) >> 3));
1.677 + c.xMc[3] = (TInt16)(((sfb(3) & 0xC0) >> 6) | ((sfb(4) & 0x01) << 2));
1.678 + c.xMc[4] = (TInt16)(((sfb(4) & 0x0E) >> 1));
1.679 + c.xMc[5] = (TInt16)(((sfb(4) & 0x70) >> 4));
1.680 + c.xMc[6] = (TInt16)(((sfb(4) & 0x80) >> 7) | ((sfb(5) & 0x03) << 1));
1.681 + c.xMc[7] = (TInt16)(((sfb(5) & 0x1C) >> 2));
1.682 + c.xMc[8] = (TInt16)(((sfb(5) & 0xE0) >> 5));
1.683 + c.xMc[9] = (TInt16)((sfb(6) & 0x07));
1.684 + c.xMc[10] = (TInt16)(((sfb(6) & 0x38) >> 3));
1.685 + c.xMc[11] = (TInt16)(((sfb(6) & 0xC0) >> 6) | ((sfb(7) & 0x01) << 2));
1.686 + c.xMc[12] = (TInt16)(((sfb(7) & 0x0E) >> 1));
1.687 +#undef sfb
1.688 + }
1.689 + }
1.690 +
1.691 +/**
1.692 +*
1.693 +* UnpackFrame1
1.694 +* @param aCodeBuf
1.695 +* @param pbuf
1.696 +*
1.697 +**/
1.698 +void CTest_MMF_Gsm610::UnpackFrame1(struct codes* aCodeBuf, TUint8* pbuf)
1.699 +{
1.700 + TInt16* LAR = aCodeBuf->LARc;
1.701 +
1.702 + // unpack the LAR[0..7] from the first 4.5 bytes
1.703 + LAR[0] = (TInt16)(((pbuf[32] & 0xF0) >> 4) | ((pbuf[33] & 0x03) << 4));
1.704 + LAR[1] = (TInt16)(((pbuf[33] & 0xFC) >> 2));
1.705 + LAR[2] = (TInt16)(((pbuf[34] & 0x1F)));
1.706 + LAR[3] = (TInt16)(((pbuf[34] & 0xE0) >> 5) | ((pbuf[35] & 0x03) << 3));
1.707 + LAR[4] = (TInt16)(((pbuf[35] & 0x3C) >> 2));
1.708 + LAR[5] = (TInt16)(((pbuf[35] & 0xC0) >> 6) | ((pbuf[36] & 0x03) << 2));
1.709 + LAR[6] = (TInt16)(((pbuf[36] & 0x1C) >> 2));
1.710 + LAR[7] = (TInt16)(((pbuf[36] & 0xE0) >> 5));
1.711 +
1.712 + // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
1.713 + for(TInt i = 0; i < 4; i++)
1.714 + {
1.715 + struct sfcodes& c = aCodeBuf->sfc[i];
1.716 +#define sfb(x) (pbuf[37+i*7+x])
1.717 + c.Nc = (TInt16)(sfb(0) & 0x7F);
1.718 + c.bc = (TInt16)(((sfb(0) & 0x80) >> 7) | ((sfb(1) & 0x01) << 1));
1.719 + c.Mc = (TInt16)(((sfb(1) & 0x06) >> 1));
1.720 + c.xmaxc = (TInt16)(((sfb(1) & 0xF8) >> 3) | ((sfb(2) & 0x01) << 5));
1.721 + c.xMc[0] = (TInt16)(((sfb(2) & 0x0E) >> 1));
1.722 + c.xMc[1] = (TInt16)(((sfb(2) & 0x70) >> 4));
1.723 + c.xMc[2] = (TInt16)(((sfb(2) & 0x80) >> 7) | ((sfb(3) & 0x03) << 1));
1.724 + c.xMc[3] = (TInt16)(((sfb(3) & 0x1C) >> 2));
1.725 + c.xMc[4] = (TInt16)(((sfb(3) & 0xE0) >> 5));
1.726 + c.xMc[5] = (TInt16)(((sfb(4) & 0x07)));
1.727 + c.xMc[6] = (TInt16)(((sfb(4) & 0x38) >> 3));
1.728 + c.xMc[7] = (TInt16)(((sfb(4) & 0xC0) >> 6) | ((sfb(5) & 0x01) << 2));
1.729 + c.xMc[8] = (TInt16)(((sfb(5) & 0x0E) >> 1));
1.730 + c.xMc[9] = (TInt16)(((sfb(5) & 0x70) >> 4));
1.731 + c.xMc[10] = (TInt16)(((sfb(5) & 0x80) >> 7) | ((sfb(6) & 0x03) << 1));
1.732 + c.xMc[11] = (TInt16)(((sfb(6) & 0x1C) >> 2));
1.733 + c.xMc[12] = (TInt16)(((sfb(6) & 0xE0) >> 5));
1.734 +
1.735 +#undef sfb
1.736 + }
1.737 + }
1.738 +
1.739 +/**
1.740 +*
1.741 +* PackFrame0
1.742 +* Pack the codewords of the even frame into pack buffer.
1.743 +* Packing as in MS gsm610 encoder.
1.744 +* @param aCodeBuf Code words for one speech frame.
1.745 +* @param pbuf the output buffer
1.746 +*
1.747 +**/
1.748 +void CTest_MMF_Gsm610::PackFrame0(struct codes* aCodeBuf, TInt8* pbuf)
1.749 + {
1.750 + TInt16* LAR = aCodeBuf->LARc;
1.751 +
1.752 + // pack the LARc[0..7] into the first 4.5 bytes
1.753 + *pbuf++ = (TUint8)(((LAR[0] ) & 0x3F) | ((LAR[1] << 6) & 0xC0));
1.754 + *pbuf++ = (TUint8)(((LAR[1] >> 2) & 0x0F) | ((LAR[2] << 4) & 0xF0));
1.755 + *pbuf++ = (TUint8)(((LAR[2] >> 4) & 0x01) | ((LAR[3] << 1) & 0x3E) | ((LAR[4] << 6) & 0xC0));
1.756 + *pbuf++ = (TUint8)(((LAR[4] >> 2) & 0x03) | ((LAR[5] << 2) & 0x3C) | ((LAR[6] << 6) & 0xC0));
1.757 + *pbuf = (TUint8)(((LAR[6] >> 2) & 0x01) | ((LAR[7] << 1) & 0x0E));
1.758 +
1.759 + // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
1.760 + for(TInt i = 0; i < 4; i++)
1.761 + {
1.762 + struct sfcodes& c = aCodeBuf->sfc[i];
1.763 + *pbuf++ |= ((c.Nc << 4) & 0xF0);
1.764 + *pbuf++ = (TUint8)(((c.Nc >> 4) & 0x07) | ((c.bc << 3) & 0x18) | ((c.Mc << 5) & 0x60) | ((c.xmaxc << 7) & 0x80));
1.765 + *pbuf++ = (TUint8)(((c.xmaxc >> 1) & 0x1F) | ((c.xMc[0] << 5) & 0xE0));
1.766 + *pbuf++ = (TUint8)((c.xMc[1] & 0x07) | ((c.xMc[2] << 3) & 0x38) | ((c.xMc[3] << 6) & 0xC0));
1.767 + *pbuf++ = (TUint8)(((c.xMc[3] >> 2) & 0x01) | ((c.xMc[4] << 1) & 0x0E) | ((c.xMc[5] << 4) & 0x70) | ((c.xMc[6] << 7) & 0x80));
1.768 + *pbuf++ = (TUint8)(((c.xMc[6] >> 1) & 0x03) | ((c.xMc[7] << 2) & 0x1C) | ((c.xMc[8] << 5) & 0xE0));
1.769 + *pbuf++ = (TUint8)((c.xMc[9] & 0x07) | ((c.xMc[10] << 3) & 0x38) | ((c.xMc[11] << 6) & 0xC0));
1.770 + *pbuf = (TUint8)(((c.xMc[11] >> 2) & 0x01) | ((c.xMc[12] << 1) & 0x0E));
1.771 + }
1.772 + }
1.773 +
1.774 +/**
1.775 +*
1.776 +* PackFrame1
1.777 +* Pack the codewords of the even frame into pack buffer.
1.778 +* Packing as in MS gsm610 encoder.
1.779 +* @param aCodeBuf Code words for one speech frame.
1.780 +* @param pbuf the output buffer
1.781 +*
1.782 +**/
1.783 +void CTest_MMF_Gsm610::PackFrame1(struct codes* aCodeBuf, TInt8* pbuf)
1.784 + {
1.785 + TInt16* LAR = aCodeBuf->LARc;
1.786 +
1.787 + pbuf += (PACKSIZE / 2);
1.788 +
1.789 + // pack the LARc[0..7] into the first 4.5 bytes, starting with the msb of the first byte
1.790 + *pbuf++ = (TUint8) (pbuf[0] | ((LAR[0] << 4) & 0xF0));
1.791 + *pbuf++ = (TUint8)(((LAR[0] >> 4) & 0x03) | ((LAR[1] << 2) & 0xFC));
1.792 + *pbuf++ = (TUint8)(((LAR[2] ) & 0x1F) | ((LAR[3] << 5) & 0xE0));
1.793 + *pbuf++ = (TUint8)(((LAR[3] >> 3) & 0x03) | ((LAR[4] << 2) & 0x3C) | ((LAR[5] << 6) & 0xC0));
1.794 + *pbuf++ = (TUint8)(((LAR[5] >> 2) & 0x03) | ((LAR[6] << 2) & 0x1C) | ((LAR[7] << 5) & 0xE0));
1.795 +
1.796 + // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
1.797 + for(TInt i = 0; i < 4; i++)
1.798 + {
1.799 + struct sfcodes& c = aCodeBuf->sfc[i];
1.800 + *pbuf++ = (TUint8)((c.Nc & 0x7F) | ((c.bc << 7) & 0x80));
1.801 + *pbuf++ = (TUint8)(((c.bc >> 1) & 0x01) | ((c.Mc << 1) & 0x06) | ((c.xmaxc << 3) & 0xF8));
1.802 + *pbuf++ = (TUint8)(((c.xmaxc >> 5) & 0x01) | ((c.xMc[0] << 1) & 0x0E) | ((c.xMc[1] << 4) & 0x70) | ((c.xMc[2] << 7) & 0x80));
1.803 + *pbuf++ = (TUint8)(((c.xMc[2] >> 1) & 0x03) | ((c.xMc[3] << 2) & 0x1C) | ((c.xMc[4] << 5) & 0xE0));
1.804 + *pbuf++ = (TUint8)(((c.xMc[5]) & 0x07) | ((c.xMc[6] << 3) & 0x38) | ((c.xMc[7] << 6) & 0xC0));
1.805 + *pbuf++ = (TUint8)(((c.xMc[7] >> 2) & 0x01) | ((c.xMc[8] << 1) & 0x0E) | ((c.xMc[9] << 4) & 0x70) | ((c.xMc[10] << 7) & 0x80));
1.806 + *pbuf++ = (TUint8)(((c.xMc[10] >> 1) & 0x03) | ((c.xMc[11] << 2) & 0x1C) | ((c.xMc[12] << 5) & 0xE0));
1.807 + }
1.808 + }
1.809 +
1.810 +/**
1.811 +*
1.812 +* CTest_MMF_SwCodecDevices_U_0001
1.813 +*
1.814 +*/
1.815 +CTest_MMF_SwCodecDevices_U_0002::CTest_MMF_SwCodecDevices_U_0002()
1.816 + {
1.817 + // store the name of this test case
1.818 + // this is the name that is used by the script file
1.819 + iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0002-HP");
1.820 + }
1.821 +/**
1.822 +*
1.823 +* CTest_MMF_SwCodecDevices_U_0001
1.824 +*
1.825 +**/
1.826 +CTest_MMF_SwCodecDevices_U_0002::~CTest_MMF_SwCodecDevices_U_0002()
1.827 + {
1.828 +
1.829 + }
1.830 +
1.831 +/**
1.832 +*
1.833 +*
1.834 +* DoTestStepL
1.835 +*
1.836 +**/
1.837 +TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepL()
1.838 + {
1.839 + __MM_HEAP_MARK;
1.840 + TVerdict result = EPass ;
1.841 +
1.842 + CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
1.843 + CleanupStack::PushL(pDecoder);
1.844 + //[ note this reference should be a ptr ]
1.845 + CMMFSwCodec& theCodec = pDecoder->Codec();
1.846 +
1.847 + //[ create buffers of the appropriate size ]
1.848 + const TInt srcBufferSize = theCodec.SourceBufferSize();
1.849 + const TInt sinkBufferSize = theCodec.SinkBufferSize();
1.850 + const TInt codedBufferSize = 76*4* KNumFramesInABuffer; // number of coded buffers * size of coded buffer 63*2
1.851 + iNumCodedFrames = KNumFramesInABuffer; //XXX claculate these constants soon <GK>
1.852 +
1.853 + iScratchData = CMMFDescriptorBuffer::NewL( codedBufferSize);
1.854 +
1.855 + iRefCodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.856 + iCodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.857 + iRefDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.858 + iDecodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize);
1.859 +
1.860 + //[ for now process only the first buffer ]
1.861 + //[encode the data]
1.862 + INFO_PRINTF1(_L("Decoding Frames..."));
1.863 + TInt codedFileSize = 0;
1.864 + iCodedFile.Size( codedFileSize);
1.865 +
1.866 + TInt numBuffers = codedFileSize/srcBufferSize;
1.867 + if(numBuffers > 4 )
1.868 + numBuffers = 4;
1.869 + TInt badBufferCount = 0;
1.870 + TInt goodBufferCount = 0;
1.871 + for( TInt bufferCount = 0; bufferCount < numBuffers; bufferCount++ )
1.872 + {
1.873 + ReadDataBufferL(iDecodeFile, *iRefDecodedData );
1.874 + ParseCodedDataL(iCodedData);
1.875 +
1.876 + CMMFSwCodec::TCodecProcessResult decodeRes = theCodec.ProcessL( *iCodedData, *iDecodedData );
1.877 + if( decodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
1.878 + {
1.879 + INFO_PRINTF1( _L("Error Failed to complete decoding") );
1.880 + return EFail;
1.881 + }
1.882 +
1.883 + //[ compare results ]
1.884 + if(!CompareDecodeResults( iDecodedData, iRefDecodedData ))
1.885 + {
1.886 + result = EFail;
1.887 + badBufferCount++;
1.888 + }
1.889 + else
1.890 + {
1.891 + goodBufferCount++;
1.892 + }
1.893 +
1.894 + }
1.895 +
1.896 + //[ log number of good frames & number of bad frames ]
1.897 + INFO_PRINTF4(_L("Good Frames %d, Bad Frames %d, Total Frames %d"),
1.898 + goodBufferCount, badBufferCount, badBufferCount+goodBufferCount );
1.899 +
1.900 + //[pop data from the cleanup stack ]
1.901 + CleanupStack::PopAndDestroy(pDecoder);
1.902 +
1.903 + delete iRefCodedData;
1.904 + iRefCodedData = NULL;
1.905 + delete iRefDecodedData;
1.906 + iRefDecodedData = NULL;
1.907 + delete iDecodedData;
1.908 + iDecodedData = NULL;
1.909 + delete iCodedData ;
1.910 + iCodedData = NULL;
1.911 + delete iScratchData;
1.912 + iScratchData = NULL;
1.913 +
1.914 + __MM_HEAP_MARKEND;
1.915 + return result;
1.916 + }
1.917 +
1.918 +/**
1.919 +*
1.920 +* DoTestStepPreambleL
1.921 +*
1.922 +*/
1.923 +enum TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepPreambleL(void)
1.924 + {
1.925 + TVerdict result = EPass;
1.926 + //[ connect to the file server ]
1.927 + User::LeaveIfError( iFs.Connect());
1.928 +
1.929 + //[ read the ref source data ]
1.930 + if(!GetStringFromConfig(_L("SectionOne"), _L("SourceData01"), iSourceDataFile) ||
1.931 + !GetStringFromConfig(_L("SectionOne"), _L("CodedData01"), iCodedDataFile) ||
1.932 + !GetStringFromConfig(_L("SectionOne"), _L("DecodedData01"), iDecodedDataFile) )
1.933 + {
1.934 + return EInconclusive;
1.935 + }
1.936 +
1.937 + //[ open the data files]
1.938 + OpenFileL(iSrcFile,iSourceDataFile );
1.939 + OpenFileL(iCodedFile,iCodedDataFile );
1.940 + OpenFileL(iDecodeFile,iDecodedDataFile);
1.941 +
1.942 + iScratchData = CMMFDescriptorBuffer::NewL(KCodedBufferSize);
1.943 +
1.944 + return result;
1.945 + }
1.946 +
1.947 +/**
1.948 +*
1.949 +* DoTestStepPostambleL
1.950 +* @result TVerdict
1.951 +*
1.952 +*/
1.953 +TVerdict CTest_MMF_SwCodecDevices_U_0002::DoTestStepPostambleL(void)
1.954 + {
1.955 + // close files
1.956 + CloseFileL( iCodedFile );
1.957 + CloseFileL( iDecodeFile );
1.958 + //[ clean up the buffers etc ]
1.959 + delete iRefSrcData; // reference source data
1.960 + delete iRefCodedData; //reference coded data
1.961 + delete iRefDecodedData; // refernce decoded data
1.962 + delete iCodedData; // buffer of coded data
1.963 + delete iDecodedData; // buffer of actual decoded data
1.964 + delete iScratchData; // scratch data buffer
1.965 + return EPass;
1.966 + }
1.967 +
1.968 +/**
1.969 +*
1.970 +* CTest_MMF_SwCodecDevices_U_0003
1.971 +*
1.972 +**/
1.973 +CTest_MMF_SwCodecDevices_U_0003::CTest_MMF_SwCodecDevices_U_0003()
1.974 + {
1.975 + // store the name of this test case
1.976 + // this is the name that is used by the script file
1.977 + iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0003-HP");
1.978 + }
1.979 +/**
1.980 +*
1.981 +* ~CTest_MMF_SwCodecDevices_U_0003
1.982 +*
1.983 +**/
1.984 +CTest_MMF_SwCodecDevices_U_0003::~CTest_MMF_SwCodecDevices_U_0003()
1.985 + {
1.986 +
1.987 + }
1.988 +
1.989 +/**
1.990 +*
1.991 +* DoTestStepL
1.992 +*
1.993 +**/
1.994 +TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepL()
1.995 + {
1.996 + __MM_HEAP_MARK;
1.997 + TVerdict result = EPass ;
1.998 +
1.999 + CMmfGsm610ToPcm16HwDevice* pDecoder = CMmfGsm610ToPcm16HwDevice::NewL();
1.1000 + CleanupStack::PushL(pDecoder);
1.1001 + //[ note this reference should be a ptr ]
1.1002 + CMMFSwCodec& theCodec = pDecoder->Codec();
1.1003 +
1.1004 + // do the same for the inverse operation
1.1005 + CMmfPcm16ToGsm610HwDevice* pEncoder = CMmfPcm16ToGsm610HwDevice::NewL();
1.1006 + CleanupStack::PushL(pEncoder);
1.1007 + CMMFSwCodec& theEncode = pEncoder->Codec();
1.1008 +
1.1009 + //[ create buffers of the appropriate size ]
1.1010 + const TInt srcBufferSize = theEncode.SourceBufferSize();
1.1011 + const TInt sinkBufferSize = theEncode.SinkBufferSize();
1.1012 +
1.1013 + iRefSrcData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.1014 + iRefCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.1015 + iRefDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.1016 + iCodedData = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.1017 + iDecodedData = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.1018 +
1.1019 + //[ now get a sine wave of 800hz, code and decode and
1.1020 + // compare the results ]
1.1021 + FillPcmBuffer( *iRefSrcData );
1.1022 +
1.1023 + // encode
1.1024 + CMMFSwCodec::TCodecProcessResult encodeRes = theEncode.ProcessL( *iRefSrcData, *iCodedData );
1.1025 + if( encodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
1.1026 + {
1.1027 + INFO_PRINTF1( _L("Error Failed to complete coding") );
1.1028 + return EFail;
1.1029 + }
1.1030 +
1.1031 + //decode
1.1032 + CMMFSwCodec::TCodecProcessResult decodeRes = theCodec.ProcessL( *iCodedData, *iDecodedData );
1.1033 + if( decodeRes != CMMFSwCodec::TCodecProcessResult::EProcessComplete )
1.1034 + {
1.1035 + INFO_PRINTF1( _L("Error Failed to complete decoding") );
1.1036 + return EFail;
1.1037 + }
1.1038 +
1.1039 + //[ because the codec overwrites its input regenerate it ]
1.1040 + FillPcmBuffer( *iRefSrcData );
1.1041 +
1.1042 + //[ NOW COMPARE THE RESULTS DISTORTION < 18 DB ]
1.1043 +
1.1044 + TUint8 *pResults = (TUint8*)(iDecodedData->Data().Ptr());
1.1045 + TUint8 *pRefData = (TUint8*)(iRefSrcData->Data().Ptr());
1.1046 + TInt numResults = iDecodedData->Data().MaxLength();
1.1047 + TReal sum1 = 0.0;
1.1048 + TReal sum2 = 0.0;
1.1049 + TReal ratio = 0.0;
1.1050 + TInt16 temp1 = 0;
1.1051 + TInt16 temp2 = 0;
1.1052 + numResults /= 2; // compensate for bytes to short conversion
1.1053 + //[print the results to allow analysis]
1.1054 + for( TInt index = 0; index < numResults; index++ )
1.1055 + {
1.1056 + temp1 = static_cast<TInt16>((*pResults++) &KAndMask8bit);
1.1057 + temp1 |= static_cast<TInt16>((*pResults++ << 8));
1.1058 + sum1 += temp1*temp1;
1.1059 + temp2 = static_cast<TInt16>((*pRefData++) &KAndMask8bit);
1.1060 + temp2 |= static_cast<TInt16>((*pRefData++ << 8));
1.1061 + sum2 += (temp2-temp1)*(temp2-temp1);
1.1062 + //INFO_PRINTF3( _L("S %d D %d"),temp2, temp1 ); // add for debugging purposes
1.1063 + }
1.1064 +
1.1065 + //[calculate the ratio ]
1.1066 + ratio = sum1;
1.1067 + ratio /=sum2;
1.1068 + TReal sn = 0.0;
1.1069 + // calculate as 18db
1.1070 + Math::Log( sn, ratio );
1.1071 + sn *= 10;
1.1072 +
1.1073 + INFO_PRINTF2( _L("Signal to Noise Ratio @800Hz %f db"), sn );
1.1074 +#ifdef EABI
1.1075 + if( sn < 18 ) //[ @800hz a sn of less than 18db is deemed a failure
1.1076 + // not that sn is a great measure of a voice coder's quality]
1.1077 + result = EFail ;
1.1078 +#else
1.1079 + if( sn < 14 ) //DEF086144 - Codec source buffer size is reduced
1.1080 + result = EFail ;
1.1081 +#endif
1.1082 + //[pop data from the cleanup stack ]
1.1083 + CleanupStack::PopAndDestroy(2, pDecoder); //pDecoder, theCodec,
1.1084 + delete iRefSrcData;
1.1085 + iRefSrcData = NULL;
1.1086 + delete iRefCodedData;
1.1087 + iRefCodedData = NULL;
1.1088 + delete iRefDecodedData;
1.1089 + iRefDecodedData = NULL;
1.1090 + delete iCodedData;
1.1091 + iCodedData = NULL;
1.1092 + delete iDecodedData;
1.1093 + iDecodedData = NULL;
1.1094 +
1.1095 + __MM_HEAP_MARKEND;
1.1096 +
1.1097 + return result;
1.1098 + }
1.1099 +
1.1100 +/**
1.1101 +*
1.1102 +* DoTestStepPreambleL
1.1103 +*
1.1104 +**/
1.1105 +TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepPreambleL(void)
1.1106 + {
1.1107 + return EPass;
1.1108 + }
1.1109 +
1.1110 +/**
1.1111 +*
1.1112 +* DoTestStepPostambleL
1.1113 +*
1.1114 +**/
1.1115 +TVerdict CTest_MMF_SwCodecDevices_U_0003::DoTestStepPostambleL(void)
1.1116 + {
1.1117 + return EPass;
1.1118 + }
1.1119 +
1.1120 +/**
1.1121 +*
1.1122 +* FillSrcBufferL
1.1123 +* @param aSrcData pointer to the src data which stores 16bit samples
1.1124 +* @param aNoSamples number of 16bit samples to store
1.1125 +* @param aOffset offset used to generate the samples (linear range)
1.1126 +**/
1.1127 +void TLawUtility::FillSrcBufferL( TUint8* aSrcData, TInt aNoSamples, TInt16 aOffset )
1.1128 + {
1.1129 + //[precondition aSrcData != NULL ]
1.1130 + if( !aSrcData )
1.1131 + User::Leave( KErrArgument );
1.1132 + const TInt16 KUpperLimit = static_cast<TInt16>(aOffset + aNoSamples);
1.1133 + TUint8* pDest = aSrcData ;
1.1134 + for( TInt16 i = aOffset; i< KUpperLimit; i++ )
1.1135 + {
1.1136 + *pDest++ = static_cast<TUint8>( i & 0xff);
1.1137 + *pDest++ = static_cast<TUint8>( (i >>8) &0xff );
1.1138 + }
1.1139 + }
1.1140 +
1.1141 +/**
1.1142 +*
1.1143 +* CompareCodedData
1.1144 +* @param aCodedData the data coded using symbian codec
1.1145 +* @param aRefCodedData the data coded using independent implementation
1.1146 +* @param aNoSamples the number of coded samples
1.1147 +*
1.1148 +**/
1.1149 +TInt TLawUtility::CompareCodedDataL(TUint8* aCodedData,TUint8* aRefCodedData, TInt aNoSamples )
1.1150 + {
1.1151 + TInt result = KErrNone;
1.1152 + //[precondition aCodedData != NULL ]
1.1153 + if( !aCodedData )
1.1154 + User::Leave( KErrArgument);
1.1155 + //[preciondition aRefCodedData != NULL ]
1.1156 + if( !aRefCodedData )
1.1157 + User::Leave( KErrArgument );
1.1158 +
1.1159 + //[ use mem compare to compare the data Buffers ]
1.1160 + if( Mem::Compare(aCodedData, aNoSamples, aRefCodedData, aNoSamples )!=0)
1.1161 + {
1.1162 + //[ data is not the same ]
1.1163 + for( TInt count = 0; count < aNoSamples; count++ )
1.1164 + {
1.1165 + //RDebug::Print(_L("c1 %u c2 %u"), *aCodedData++, *aRefCodedData++); Statement commented under DEF105143
1.1166 + *aCodedData++;
1.1167 + *aRefCodedData++;
1.1168 + }
1.1169 + result = KErrCorrupt;
1.1170 + }
1.1171 +
1.1172 + return result;
1.1173 + }
1.1174 +
1.1175 +/**
1.1176 +*
1.1177 +* AssembleValL
1.1178 +* @param aDecodedData
1.1179 +* @return decoded value
1.1180 +*
1.1181 +**/
1.1182 +TInt16 TLawUtility::AssembleValL(TUint8* aDecodedData)
1.1183 + {
1.1184 + TInt16 val;
1.1185 + if(!aDecodedData )
1.1186 + User::Leave( KErrArgument);
1.1187 +
1.1188 + //assemble the value
1.1189 + val = static_cast<TInt16>( aDecodedData[0] &KAndMask8bit);
1.1190 + val |= static_cast<TInt16>((aDecodedData[1] << 8 ));
1.1191 +
1.1192 + return val;
1.1193 + }
1.1194 +
1.1195 +/**
1.1196 +*
1.1197 +* SNRatio
1.1198 +*
1.1199 +**/
1.1200 +TReal TLawUtility::SNRatioL(TUint8* aDecodedData, TUint8* aSrcData, TInt aNoSamples )
1.1201 + {
1.1202 + const TReal KThreshold = 0.0001;
1.1203 + TReal ratio = 0.0;
1.1204 + //[precondition aDecodedData != NULL ]
1.1205 + if( !aDecodedData )
1.1206 + User::Leave( KErrArgument );
1.1207 + //[ precondition aSrcData != NULL ]
1.1208 + if( !aSrcData )
1.1209 + User::Leave( KErrArgument );
1.1210 +
1.1211 + TReal sumSig = 0.0; // numerator
1.1212 + TReal sumNoise = 0.0; // denominator
1.1213 + TInt difference = 0;
1.1214 + TInt16 dataValue = 0;
1.1215 + TInt decodeVal = 0;
1.1216 + for( TInt count = 0; count < aNoSamples; count++ )
1.1217 + {
1.1218 + decodeVal = AssembleValL(aDecodedData);
1.1219 + dataValue = AssembleValL(aSrcData);
1.1220 + difference = decodeVal - dataValue;
1.1221 + sumSig += (decodeVal*decodeVal); // sum of the squares of the signal
1.1222 + sumNoise += (difference * difference ); // sum of the square of the difference
1.1223 + aDecodedData+=2;
1.1224 + aSrcData+=2;
1.1225 + }
1.1226 +
1.1227 + //[ guard against division by zero ]
1.1228 + if( !( sumNoise >= KThreshold ))
1.1229 + User::Leave( KErrUnderflow );
1.1230 +
1.1231 + //[ calculate the sn ratio ]
1.1232 + //[ 10log10( sumSig/SumNoise ]
1.1233 + Math::Log( ratio, (sumSig/sumNoise) );
1.1234 + ratio *= 10; // ratio = 10*log( x**2/(error**2)) in db
1.1235 + return ratio;
1.1236 + }
1.1237 +
1.1238 +/**
1.1239 +*
1.1240 +* CompareSNRatiosL
1.1241 +* @param aCodecSN codec under test SN ratio in db
1.1242 +* @param aCodecSN2 refernce codec SN ratio in db
1.1243 +* @param aThreshold difference allowed in db
1.1244 +* @result within tolerance
1.1245 +*
1.1246 +**/
1.1247 +TBool TLawUtility::CompareSNRatiosL( TReal aCodecSN, TReal aCodecSN2, TReal aTolerance )
1.1248 + {
1.1249 + TBool result = ETrue;
1.1250 + TReal difference = (aCodecSN - aCodecSN2);
1.1251 + //[ it would be nice to replace this with a abs function ?]
1.1252 + if( difference < 0.0 )
1.1253 + {
1.1254 + if( aTolerance > difference )
1.1255 + {
1.1256 + result = EFalse;
1.1257 + }
1.1258 + }
1.1259 + else
1.1260 + {
1.1261 + if( aTolerance < difference )
1.1262 + {
1.1263 + result = EFalse;
1.1264 + }
1.1265 + }
1.1266 +
1.1267 + return result;
1.1268 + }
1.1269 +
1.1270 +/**
1.1271 +*
1.1272 +* ComputeSNL compute the Signal to Noise Ratio
1.1273 +*
1.1274 +**/
1.1275 +TReal TLawUtility::ComputeSNL( TReal aSumSigSquared, TReal aSumErrorSquared )
1.1276 + {
1.1277 + TReal sn = 0.0;
1.1278 + const TReal tolerance = 0.001;
1.1279 + //[precondition error is >= tolerance ]
1.1280 + if( aSumErrorSquared < tolerance )
1.1281 + User::Leave( KErrArgument );
1.1282 + //[claculate ratio safely ]
1.1283 + Math::Log( sn, (aSumSigSquared/aSumErrorSquared));
1.1284 + sn*= 10;
1.1285 + return sn;
1.1286 + }
1.1287 +
1.1288 +/**
1.1289 +*
1.1290 +* SumSquaredL
1.1291 +*
1.1292 +**/
1.1293 +TReal TLawUtility::SumSquaredL( TUint8* aData, TInt aNoSamples )
1.1294 + {
1.1295 + //[precondition arg is ok ]
1.1296 + if( !aData )
1.1297 + {
1.1298 + User::Leave(KErrArgument);
1.1299 + }
1.1300 +
1.1301 + TUint8* pData = aData;
1.1302 + TInt16 sample ;
1.1303 + TReal sumSigSquared = 0.0;
1.1304 + for( TInt count = 0; count < aNoSamples; count++ )
1.1305 + {
1.1306 + sample = static_cast<TInt16>( pData[0] &KAndMask8bit);
1.1307 + sample |= static_cast<TInt16>((pData[1] << 8 ));
1.1308 + sumSigSquared += (sample*sample);
1.1309 + pData+=2;
1.1310 + }
1.1311 +
1.1312 + return sumSigSquared;
1.1313 + }
1.1314 +
1.1315 +/**
1.1316 +*
1.1317 +* SumErrorSquaredL
1.1318 +* @param aData
1.1319 +* @param aData2
1.1320 +* @param aNoSamples
1.1321 +* @result TReal
1.1322 +*
1.1323 +**/
1.1324 +TReal TLawUtility::SumErrorSquaredL( TUint8* aData, TUint8* aData2, TInt aNoSamples )
1.1325 + {
1.1326 + //[precondition aData is not NULL]
1.1327 + if( !aData )
1.1328 + {
1.1329 + User::Leave(KErrArgument);
1.1330 + }
1.1331 +
1.1332 + //[precondition aData2 is not NULL ]
1.1333 + if( !aData2 )
1.1334 + {
1.1335 + User::Leave(KErrArgument);
1.1336 + }
1.1337 +
1.1338 + TUint8* pData = aData;
1.1339 + TUint8* pData2 = aData2;
1.1340 + TInt16 sample ;
1.1341 + TInt16 sample2;
1.1342 + TReal sumErrorSquared = 0.0;
1.1343 + TInt error;
1.1344 + for( TInt count = 0; count < aNoSamples; count++ )
1.1345 + {
1.1346 + error = 0;
1.1347 + sample = static_cast<TInt16>( pData[0] &KAndMask8bit);
1.1348 + sample |= static_cast<TInt16>((pData[1] << 8 ));
1.1349 + sample2 = static_cast<TInt16>( pData2[0] &KAndMask8bit);
1.1350 + sample2 |= static_cast<TInt16>((pData2[1] << 8 ));
1.1351 + error = sample -sample2; // compute the error
1.1352 + sumErrorSquared += (error*error); // add error squared to the sum
1.1353 + pData +=2;
1.1354 + pData2 +=2;
1.1355 + }
1.1356 +
1.1357 + return sumErrorSquared;
1.1358 + }
1.1359 +
1.1360 +/**
1.1361 +*
1.1362 +* CTestMuLawCodec_U_0006
1.1363 +*
1.1364 +**/
1.1365 +CTestMuLawCodec_U_0006::CTestMuLawCodec_U_0006()
1.1366 + {
1.1367 + //[ set test name]
1.1368 + iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0006-HP");
1.1369 + }
1.1370 +
1.1371 +/**
1.1372 +*
1.1373 +* LinearToMuLawSample
1.1374 +* @param aSample a 16 bit pcm sample
1.1375 +* @result Mu Law encoded sample
1.1376 +*
1.1377 +**/
1.1378 +TUint8 CTestMuLawCodec_U_0006::LinearToMuLawSample( TInt16 aSample)
1.1379 + {
1.1380 + const int KBias = 0x84;
1.1381 + const int KClip = 32635;
1.1382 + TInt sign = (aSample >> 8) & 0x80;
1.1383 + if(sign)
1.1384 + aSample = static_cast<TInt16>(-aSample);
1.1385 + if(aSample > KClip)
1.1386 + aSample = KClip;
1.1387 + aSample = static_cast<TInt16>(aSample + KBias);
1.1388 + TInt exponent = static_cast<TInt>( MuLawCompressTable[(aSample>>7) & 0xFF]);
1.1389 + TInt mantissa = (aSample >> (exponent+3)) & 0x0F;
1.1390 + TInt compressedByte = ~(sign | (exponent << 4) | mantissa);
1.1391 + return static_cast<TUint8>( compressedByte );
1.1392 + }
1.1393 +
1.1394 +/**
1.1395 +*
1.1396 +* ConvertPcmMuLaw
1.1397 +*
1.1398 +**/
1.1399 +void CTestMuLawCodec_U_0006::ConvertPcmMuLawL(TUint8* aSrcData, TUint8* aCodedData, TInt aNumSamples )
1.1400 + {
1.1401 + //[ precondition aSrcData ]
1.1402 + if( !aSrcData )
1.1403 + User::Leave( KErrArgument );
1.1404 + //[precondition aCodedData ]
1.1405 + if( !aCodedData )
1.1406 + User::Leave( KErrArgument );
1.1407 +
1.1408 + TUint8* pCoded = aCodedData;
1.1409 + TUint8* pData = aSrcData ;
1.1410 + TInt16 pcmSample;
1.1411 + for( TInt count = 0; count < aNumSamples; count++ )
1.1412 + {
1.1413 + //[ code the data ]
1.1414 + pcmSample = static_cast<TInt16>(pData[0]);
1.1415 + pcmSample |= static_cast<TInt16>((pData[1] << 8 ));
1.1416 + *pCoded++ = LinearToMuLawSample(pcmSample);
1.1417 + pData+=2;
1.1418 + }
1.1419 + }
1.1420 +
1.1421 +/**
1.1422 +*
1.1423 +* ConvertMuLawPcm
1.1424 +*
1.1425 +**/
1.1426 +void CTestMuLawCodec_U_0006::ConvertMuLawPcmL(TUint8* aCoded, TUint8* aDecoded, TInt aNumSamples )
1.1427 + {
1.1428 + //[ precondition aCoded ]
1.1429 + if( !aCoded )
1.1430 + User::Leave( KErrArgument );
1.1431 + //[precondition aDecoded ]
1.1432 + if( !aDecoded )
1.1433 + User::Leave( KErrArgument );
1.1434 +
1.1435 + TInt16 pcmSample;
1.1436 + TUint8* pCoded = aCoded;
1.1437 + TUint8* pDecoded = aDecoded;
1.1438 + //[ lets convert the data ]
1.1439 + for(TInt count = 0; count < aNumSamples; count++ )
1.1440 + {
1.1441 + pcmSample = MuLawDecompressTable[*pCoded++];
1.1442 + *pDecoded++ = static_cast<TUint8>( pcmSample & 0xFF);
1.1443 + *pDecoded++ = static_cast<TUint8>((pcmSample >> 8 ) & 0xFF);
1.1444 + }
1.1445 + }
1.1446 +
1.1447 +/**
1.1448 +*
1.1449 +* DoTestStepL
1.1450 +*
1.1451 +**/
1.1452 +TVerdict CTestMuLawCodec_U_0006::DoTestStepL()
1.1453 + {
1.1454 + TVerdict result = EPass;
1.1455 + const TInt KSrcBufferSize = 400; // small buffer size
1.1456 + const TInt KHalfSrcBufferSize = 200; // small buffer size
1.1457 + const TInt KCodedBufferSize = 200; // small buffer size
1.1458 + const TInt KLowerLimit = -800; //lower limit of test range
1.1459 + const TInt KUpperLimit = 800; // upper limit of test range +1
1.1460 +
1.1461 + //[ allocate memory buffers]
1.1462 + TUint8* pSymbianSrcData = new(ELeave)TUint8[KSrcBufferSize];
1.1463 + CleanupStack::PushL(pSymbianSrcData);
1.1464 + TUint8* pIndependentSrcData = new(ELeave)TUint8[KSrcBufferSize];
1.1465 + CleanupStack::PushL(pIndependentSrcData);
1.1466 + TUint8* pSymbianCodedData = new(ELeave)TUint8[KCodedBufferSize];
1.1467 + CleanupStack::PushL(pSymbianCodedData);
1.1468 + TUint8* pIndependentCodedData = new(ELeave)TUint8[KCodedBufferSize];
1.1469 + CleanupStack::PushL(pIndependentCodedData);
1.1470 + TUint8* pSymbianDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1.1471 + CleanupStack::PushL(pSymbianDecodedData);
1.1472 + TUint8* pIndependentDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1.1473 + CleanupStack::PushL(pIndependentDecodedData);
1.1474 +
1.1475 + TMMFAudioMuLawToS16PcmCodec decoder;
1.1476 + TMMFAudioSPcm16ToMuLawCodec encoder;
1.1477 +
1.1478 + TLawUtility helper;
1.1479 + TReal symbianCodecSN = 0.0;
1.1480 + TReal independentCodecSN = 0.0;
1.1481 +
1.1482 + TReal sumRefSig = 0.0; // sum of sig squared
1.1483 + TReal sumRefError = 0.0; // sum of error sig squared
1.1484 + TReal sumSymbianSig = 0.0; // sum of sig squared
1.1485 + TReal sumSymbianError = 0.0; // sum of error sig squared
1.1486 +
1.1487 + //[ interate over a suitable range and process each buffer]
1.1488 + for( TInt index = KLowerLimit; index < KUpperLimit; index+= KHalfSrcBufferSize )
1.1489 + {
1.1490 + TInt16 offset = static_cast<TInt16>( index);
1.1491 + //[ fill the src buffers ]
1.1492 + helper.FillSrcBufferL( pSymbianSrcData, KHalfSrcBufferSize, offset );
1.1493 + helper.FillSrcBufferL( pIndependentSrcData, KHalfSrcBufferSize, offset );
1.1494 +
1.1495 + //[encode the src data ]
1.1496 + encoder.Convert( pSymbianSrcData, pSymbianCodedData, KHalfSrcBufferSize );
1.1497 + ConvertPcmMuLawL(pIndependentSrcData,pIndependentCodedData,KHalfSrcBufferSize );
1.1498 +
1.1499 + //[ decode the data ]
1.1500 + decoder.Convert( pSymbianCodedData, pSymbianDecodedData, KHalfSrcBufferSize );
1.1501 + ConvertMuLawPcmL( pIndependentCodedData,pIndependentDecodedData,KHalfSrcBufferSize);
1.1502 +
1.1503 + //[ check both codecs code the data similarly]
1.1504 + TInt errorCode =helper.CompareCodedDataL(pIndependentCodedData, pSymbianCodedData, KHalfSrcBufferSize );
1.1505 + if( errorCode != KErrNone )
1.1506 + {
1.1507 + INFO_PRINTF1(_L("Forward Transformation for Mu-Law codec is not conformant to ref codec"));
1.1508 + User::LeaveIfError(errorCode);
1.1509 + }
1.1510 + //[ upate running total sums to be used for signal to noise
1.1511 + // ratio calculations ]
1.1512 + sumRefSig += helper.SumSquaredL(pIndependentSrcData, KHalfSrcBufferSize);
1.1513 + sumRefError += helper.SumErrorSquaredL(pIndependentSrcData,pIndependentDecodedData,KHalfSrcBufferSize);
1.1514 + sumSymbianSig += helper.SumSquaredL(pSymbianSrcData,KHalfSrcBufferSize);
1.1515 + sumSymbianError += helper.SumErrorSquaredL(pSymbianSrcData,pSymbianDecodedData,KHalfSrcBufferSize);
1.1516 + }
1.1517 +
1.1518 + const TReal KTolerance = 1; // allow for a 1 db tolerance
1.1519 + symbianCodecSN = helper.ComputeSNL(sumSymbianSig,sumSymbianError);
1.1520 + independentCodecSN = helper.ComputeSNL(sumRefSig, sumRefError);
1.1521 + // Gamma = (dynamic range of codec /signal std deviation )
1.1522 + INFO_PRINTF1(_L("We would expect S/N ration to be greater than 35db for an MuLaw codec with Gamma = 10"));
1.1523 + INFO_PRINTF2(_L("Signal/Noise Ratio Symbian Codec %f"), symbianCodecSN );
1.1524 + INFO_PRINTF2(_L("Signal/Noise Ratio Reference Codec %f"), independentCodecSN );
1.1525 +
1.1526 + //[ compare the s/n ratio's of the two codec implementations]
1.1527 + if( !helper.CompareSNRatiosL( symbianCodecSN, independentCodecSN, KTolerance ))
1.1528 + {
1.1529 + //[ fail the test because the s/n ratios were divergent ]
1.1530 + result = EFail;
1.1531 + }
1.1532 + CleanupStack::PopAndDestroy(6,pSymbianSrcData); //pSymbianSrcData,pIndependentSrcData,
1.1533 + //pSymbianCodedData,pIndependentCodedData
1.1534 + //pSymbianDecodedData,pIndependentDecodedData
1.1535 +
1.1536 + return result;
1.1537 + }
1.1538 +
1.1539 +/**
1.1540 +*
1.1541 +* DoTestStepPreambleL
1.1542 +*
1.1543 +**/
1.1544 +TVerdict CTestMuLawCodec_U_0006::DoTestStepPreambleL(void)
1.1545 + {
1.1546 + TVerdict result = EPass;
1.1547 + return result; //nothing doing
1.1548 + }
1.1549 +
1.1550 +/**
1.1551 +*
1.1552 +* DoTestStepPostambleL
1.1553 +*
1.1554 +**/
1.1555 +TVerdict CTestMuLawCodec_U_0006::DoTestStepPostambleL(void)
1.1556 + {
1.1557 + TVerdict result = EPass;
1.1558 + return result; //nothing doing
1.1559 + }
1.1560 +
1.1561 +/**
1.1562 +*
1.1563 +* Mu-Law Compression Table
1.1564 +*
1.1565 +**/
1.1566 +const TInt8 CTestMuLawCodec_U_0006::MuLawCompressTable[PcmToMuLawCompressionTableSize] =
1.1567 +{
1.1568 +0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
1.1569 +4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1.1570 +5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1.1571 +5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1.1572 +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.1573 +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.1574 +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.1575 +6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.1576 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1577 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1578 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1579 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1580 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1581 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1582 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.1583 +7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
1.1584 +};
1.1585 +
1.1586 +/**
1.1587 +*
1.1588 +* Mu-Law Decompression Table
1.1589 +*
1.1590 +**/
1.1591 +const TInt16 CTestMuLawCodec_U_0006::MuLawDecompressTable[MuLawToPcmCompressionTableSize]=
1.1592 +{
1.1593 +-32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
1.1594 +-23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
1.1595 +-15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
1.1596 +-11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
1.1597 +-7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
1.1598 +-5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
1.1599 +-3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
1.1600 +-2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
1.1601 +-1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
1.1602 +-1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
1.1603 +-876, -844, -812, -780, -748, -716, -684, -652,
1.1604 +-620, -588, -556, -524, -492, -460, -428, -396,
1.1605 +-372, -356, -340, -324, -308, -292, -276, -260,
1.1606 +-244, -228, -212, -196, -180, -164, -148, -132,
1.1607 +-120, -112, -104, -96, -88, -80, -72, -64,
1.1608 +-56, -48, -40, -32, -24, -16, -8, 0,
1.1609 +32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
1.1610 +23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
1.1611 +15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
1.1612 +11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
1.1613 +7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
1.1614 +5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
1.1615 +3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
1.1616 +2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
1.1617 +1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
1.1618 +1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
1.1619 +876, 844, 812, 780, 748, 716, 684, 652,
1.1620 +620, 588, 556, 524, 492, 460, 428, 396,
1.1621 +372, 356, 340, 324, 308, 292, 276, 260,
1.1622 +244, 228, 212, 196, 180, 164, 148, 132,
1.1623 +120, 112, 104, 96, 88, 80, 72, 64,
1.1624 +56, 48, 40, 32, 24, 16, 8, 0
1.1625 +};
1.1626 +
1.1627 +/**
1.1628 +*
1.1629 +* CTestALawCodec_U_0004
1.1630 +*
1.1631 +**/
1.1632 +CTestALawCodec_U_0004::CTestALawCodec_U_0004()
1.1633 + {
1.1634 + //[ set test name ]
1.1635 + iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0004-HP");
1.1636 + }
1.1637 +
1.1638 +/**
1.1639 +*
1.1640 +* ConvertPcmALaw converts Pcm 16 to 8bit ALaw
1.1641 +* @param aSrcData The src data
1.1642 +* @param aCoded The coded result
1.1643 +* @param aNumSamples The number of samples to be processed
1.1644 +* @precondition aSrcData is not NULL
1.1645 +* @precondition aCodedData is not NULL
1.1646 +* @precondition there is sufficient room in the destination
1.1647 +* to contain the coded samples
1.1648 +*
1.1649 +**/
1.1650 +void CTestALawCodec_U_0004::ConvertPcmALawL(TUint8* aSrcData, TUint8* aCodedData, TInt aNumSamples )
1.1651 + {
1.1652 + //[ precondition aSrcData ]
1.1653 + if( !aSrcData )
1.1654 + User::Leave( KErrArgument );
1.1655 + //[precondition aCodedData ]
1.1656 + if( !aCodedData )
1.1657 + User::Leave( KErrArgument );
1.1658 +
1.1659 + TUint8* pCoded = aCodedData;
1.1660 + TUint8* pData = aSrcData ;
1.1661 + TInt16 pcmSample;
1.1662 + for( TInt count = 0; count < aNumSamples; count++ )
1.1663 + {
1.1664 + //[ code the data ]
1.1665 + pcmSample = static_cast<TInt16>(pData[0]);
1.1666 + pcmSample |= static_cast<TInt16>((pData[1] << 8 ));
1.1667 + *pCoded++ = LinearToALawSample(pcmSample);
1.1668 + pData+=2;
1.1669 + }
1.1670 + }
1.1671 +
1.1672 +/**
1.1673 +*
1.1674 +* ConvertALawPcm converts from 8bit ALaw to Pcm16
1.1675 +* @param aCoded The coded data
1.1676 +* @param aDecoded The decoded result
1.1677 +* @param aNumSamples The number of samples to be processed
1.1678 +* @precondition aCoded is not NULL
1.1679 +* @precondition aDecoded is not NULL
1.1680 +* @precondition there is sufficient room in the destination
1.1681 +* to contain the coded samples
1.1682 +*
1.1683 +**/
1.1684 +void CTestALawCodec_U_0004::ConvertALawPcmL(TUint8* aCoded, TUint8* aDecoded, TInt aNumSamples )
1.1685 + {
1.1686 + //[ precondition aSrcData ]
1.1687 + if( !aCoded )
1.1688 + User::Leave( KErrArgument );
1.1689 + //[precondition aCodedData ]
1.1690 + if( !aDecoded )
1.1691 + User::Leave( KErrArgument );
1.1692 +
1.1693 + TInt16 pcmSample;
1.1694 + TUint8* pCoded = aCoded;
1.1695 + TUint8* pDecoded = aDecoded;
1.1696 + //[ lets convert the data ]
1.1697 + for(TInt count = 0; count < aNumSamples; count++ )
1.1698 + {
1.1699 + pcmSample = ALawDecompressTable[*pCoded++];
1.1700 + *pDecoded++ = static_cast<TUint8>(pcmSample & 0xFF);
1.1701 + *pDecoded++ = static_cast<TUint8>((pcmSample >> 8 ) & 0xFF);
1.1702 + }
1.1703 + }
1.1704 +
1.1705 +/**
1.1706 +*
1.1707 +* LinearToALawSample converts a Pcm16 sample to ALaw
1.1708 +* @param aSample the PCM 16 sample to be converted
1.1709 +* @result coded result
1.1710 +*
1.1711 +**/
1.1712 +TUint8 CTestALawCodec_U_0004::LinearToALawSample(TInt16 aSample)
1.1713 + {
1.1714 + const TInt KClip = 32635;
1.1715 + TInt sign;
1.1716 + TInt exponent;
1.1717 + TInt mantissa;
1.1718 + TUint8 compressedByte;
1.1719 + sign = ((~aSample) >> 8) & 0x80;
1.1720 + if(!sign)
1.1721 + aSample = static_cast<TInt16>(-aSample);
1.1722 + if(aSample > KClip)
1.1723 + aSample = KClip;
1.1724 + if(aSample >= 256)
1.1725 + {
1.1726 + exponent = static_cast<TInt>( ALawCompressTable[(aSample >> 8) & 0x7F]);
1.1727 + mantissa = (aSample >> (exponent + 3) ) & 0x0F;
1.1728 + compressedByte = static_cast<TUint8> ((exponent << 4) | mantissa);
1.1729 + }
1.1730 + else
1.1731 + {
1.1732 + compressedByte = static_cast<TUint8> (aSample >> 4);
1.1733 + }
1.1734 + compressedByte ^= (sign ^ 0x55);
1.1735 + return compressedByte;
1.1736 + }
1.1737 +
1.1738 +/**
1.1739 +*
1.1740 +* DoTestStepL
1.1741 +*
1.1742 +**/
1.1743 +TVerdict CTestALawCodec_U_0004::DoTestStepL()
1.1744 + {
1.1745 + TVerdict result = EPass;
1.1746 + const TInt KSrcBufferSize = 400; // small buffer size
1.1747 + const TInt KHalfSrcBufferSize = 200; // small buffer size
1.1748 + const TInt KCodedBufferSize = 200; // small buffer size
1.1749 + const TInt KLowerLimit = -400; //lower limit of test range
1.1750 + const TInt KUpperLimit = 400; // upper limit of test range +1
1.1751 +
1.1752 + //[ allocate memory buffers]
1.1753 + TUint8* pSymbianSrcData = new(ELeave)TUint8[KSrcBufferSize];
1.1754 + CleanupStack::PushL(pSymbianSrcData);
1.1755 + TUint8* pIndependentSrcData = new(ELeave)TUint8[KSrcBufferSize];
1.1756 + CleanupStack::PushL(pIndependentSrcData);
1.1757 + TUint8* pSymbianCodedData = new(ELeave)TUint8[KCodedBufferSize];
1.1758 + CleanupStack::PushL(pSymbianCodedData);
1.1759 + TUint8* pIndependentCodedData = new(ELeave)TUint8[KCodedBufferSize];
1.1760 + CleanupStack::PushL(pIndependentCodedData);
1.1761 + TUint8* pSymbianDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1.1762 + CleanupStack::PushL(pSymbianDecodedData);
1.1763 + TUint8* pIndependentDecodedData = new(ELeave)TUint8[KSrcBufferSize];
1.1764 + CleanupStack::PushL(pIndependentDecodedData);
1.1765 +
1.1766 + TMMFAudioSPcm16ToAlawCodec encoder;
1.1767 + TMMFAudioALawToS16PcmCodec decoder;
1.1768 +
1.1769 + TLawUtility helper;
1.1770 + TReal symbianCodecSN = 0.0;
1.1771 + TReal independentCodecSN = 0.0;
1.1772 +
1.1773 + TReal sumRefSig = 0.0; // sum of sig squared
1.1774 + TReal sumRefError = 0.0; // sum of error sig squared
1.1775 + TReal sumSymbianSig = 0.0; // sum of sig squared
1.1776 + TReal sumSymbianError = 0.0; // sum of error sig squared
1.1777 +
1.1778 + //[ interate over a suitable range and process each buffer]
1.1779 + for( TInt index = KLowerLimit; index < KUpperLimit; index+= KHalfSrcBufferSize )
1.1780 + {
1.1781 + TInt16 offset = static_cast<TInt16>( index);
1.1782 + //[ fill the src buffers ]
1.1783 + helper.FillSrcBufferL( pSymbianSrcData, KHalfSrcBufferSize, offset );
1.1784 + helper.FillSrcBufferL( pIndependentSrcData, KHalfSrcBufferSize, offset );
1.1785 +
1.1786 + //[encode the src data ]
1.1787 + encoder.Convert( pSymbianSrcData, pSymbianCodedData, KHalfSrcBufferSize );
1.1788 + ConvertPcmALawL(pIndependentSrcData,pIndependentCodedData,KHalfSrcBufferSize );
1.1789 +
1.1790 + //[ decode the data ]
1.1791 + decoder.Convert( pSymbianCodedData, pSymbianDecodedData, KHalfSrcBufferSize );
1.1792 + ConvertALawPcmL( pIndependentCodedData,pIndependentDecodedData,KHalfSrcBufferSize);
1.1793 +
1.1794 + //[ check both codecs code the data similarly]
1.1795 + TInt errorCode = helper.CompareCodedDataL(pIndependentCodedData, pSymbianCodedData, KHalfSrcBufferSize );
1.1796 + if( errorCode != KErrNone )
1.1797 + {
1.1798 + INFO_PRINTF1(_L("Forward Transformation for ALaw codec is not conformant to ref codec"));
1.1799 + User::LeaveIfError(errorCode);
1.1800 + }
1.1801 +
1.1802 + //[ upate running total sums to be used for signal to noise
1.1803 + // ratio calculations ]
1.1804 + sumRefSig += helper.SumSquaredL(pIndependentSrcData, KHalfSrcBufferSize);
1.1805 + sumRefError += helper.SumErrorSquaredL(pIndependentSrcData,pIndependentDecodedData,KHalfSrcBufferSize);
1.1806 + sumSymbianSig += helper.SumSquaredL(pSymbianSrcData,KHalfSrcBufferSize);
1.1807 + sumSymbianError += helper.SumErrorSquaredL(pSymbianSrcData,pSymbianDecodedData,KHalfSrcBufferSize);
1.1808 + }
1.1809 + const TReal KTolerance = 1; // allow for a 1 db tolerance
1.1810 + symbianCodecSN = helper.ComputeSNL(sumSymbianSig,sumSymbianError);
1.1811 + independentCodecSN = helper.ComputeSNL(sumRefSig, sumRefError);
1.1812 + // Gamma = (dynamic range of codec /signal std deviation )
1.1813 + INFO_PRINTF1(_L("We would expect S/N ration to be greater than 30db for an ALaw codec with Gamma = 10"));
1.1814 + INFO_PRINTF2(_L("Signal/Noise Ratio Symbian Codec %f"), symbianCodecSN );
1.1815 + INFO_PRINTF2(_L("Signal/Noise Ratio Reference Codec %f"), independentCodecSN );
1.1816 +
1.1817 + //[ compare the s/n ratio's of the two codec implementations]
1.1818 + if( !helper.CompareSNRatiosL( symbianCodecSN, independentCodecSN, KTolerance ))
1.1819 + {
1.1820 + //[ fail the test because the s/n ratios were divergent ]
1.1821 + result = EFail;
1.1822 + }
1.1823 +
1.1824 + CleanupStack::PopAndDestroy(6,pSymbianSrcData); //pSymbianSrcData,pIndependentSrcData,
1.1825 + //pSymbianCodedData,pIndependentCodedData
1.1826 + //pSymbianDecodedData,pIndependentDecodedData
1.1827 + return result;
1.1828 + }
1.1829 +
1.1830 +/**
1.1831 +*
1.1832 +* DoTestStepPreambleL
1.1833 +*
1.1834 +**/
1.1835 +TVerdict CTestALawCodec_U_0004::DoTestStepPreambleL(void)
1.1836 + {
1.1837 + TVerdict result = EPass;
1.1838 + return result; //nothing doing
1.1839 + }
1.1840 +/**
1.1841 +*
1.1842 +* DoTestStepPostambleL
1.1843 +*
1.1844 +**/
1.1845 +TVerdict CTestALawCodec_U_0004::DoTestStepPostambleL(void)
1.1846 + {
1.1847 + TVerdict result = EPass;
1.1848 + return result; //nothing doing
1.1849 + }
1.1850 +/**
1.1851 +*
1.1852 +* ALaw Compression Table
1.1853 +*
1.1854 +**/
1.1855 +const TInt8 CTestALawCodec_U_0004::ALawCompressTable[PcmToALawCompressionTableSize] =
1.1856 +{
1.1857 +1,1,2,2,3,3,3,3,
1.1858 +4,4,4,4,4,4,4,4,
1.1859 +5,5,5,5,5,5,5,5,
1.1860 +5,5,5,5,5,5,5,5,
1.1861 +6,6,6,6,6,6,6,6,
1.1862 +6,6,6,6,6,6,6,6,
1.1863 +6,6,6,6,6,6,6,6,
1.1864 +6,6,6,6,6,6,6,6,
1.1865 +7,7,7,7,7,7,7,7,
1.1866 +7,7,7,7,7,7,7,7,
1.1867 +7,7,7,7,7,7,7,7,
1.1868 +7,7,7,7,7,7,7,7,
1.1869 +7,7,7,7,7,7,7,7,
1.1870 +7,7,7,7,7,7,7,7,
1.1871 +7,7,7,7,7,7,7,7,
1.1872 +7,7,7,7,7,7,7,7
1.1873 +};
1.1874 +
1.1875 +/**
1.1876 +*
1.1877 +* ALaw Decompression Table
1.1878 +*
1.1879 +**/
1.1880 +const TInt16 CTestALawCodec_U_0004::ALawDecompressTable[ALawToPcmCompressionTableSize] =
1.1881 +{
1.1882 +-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
1.1883 +-7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
1.1884 +-2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
1.1885 +-3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
1.1886 +-22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,
1.1887 +-30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,
1.1888 +-11008,-10496,-12032,-11520,-8960, -8448, -9984, -9472,
1.1889 +-15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,
1.1890 +-344, -328, -376, -360, -280, -264, -312, -296,
1.1891 +-472, -456, -504, -488, -408, -392, -440, -424,
1.1892 +-88, -72, -120, -104, -24, -8, -56, -40,
1.1893 +-216, -200, -248, -232, -152, -136, -184, -168,
1.1894 +-1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
1.1895 +-1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
1.1896 +-688, -656, -752, -720, -560, -528, -624, -592,
1.1897 +-944, -912, -1008, -976, -816, -784, -880, -848,
1.1898 +5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
1.1899 +7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
1.1900 +2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
1.1901 +3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
1.1902 +22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
1.1903 +30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
1.1904 +11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
1.1905 +15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
1.1906 +344, 328, 376, 360, 280, 264, 312, 296,
1.1907 +472, 456, 504, 488, 408, 392, 440, 424,
1.1908 +88, 72, 120, 104, 24, 8, 56, 40,
1.1909 +216, 200, 248, 232, 152, 136, 184, 168,
1.1910 +1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
1.1911 +1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
1.1912 +688, 656, 752, 720, 560, 528, 624, 592,
1.1913 +944, 912, 1008, 976, 816, 784, 880, 848
1.1914 +};
1.1915 +
1.1916 +/**
1.1917 +*
1.1918 +* CTestIMaadCodec
1.1919 +*
1.1920 +**/
1.1921 +CTestIMaadCodec::CTestIMaadCodec()
1.1922 + {
1.1923 + //[ set test name ]
1.1924 + iTestStepName = _L("MM-MMF-SWCODECDEVICES-U-0022-HP");
1.1925 + }
1.1926 +
1.1927 +/**
1.1928 +*
1.1929 +* DoTestStepL
1.1930 +*
1.1931 +**/
1.1932 +TVerdict CTestIMaadCodec::DoTestStepL()
1.1933 + {
1.1934 + __MM_HEAP_MARK;
1.1935 + TVerdict result = EPass;
1.1936 + TInt srcBufferSize;
1.1937 + TInt sinkBufferSize;
1.1938 + const TReal KExpectedSNRatioDb = 30.0; //30 db for now
1.1939 +
1.1940 + //[ Create coder and decoder codecs ]
1.1941 + CMMFPcm16ToImaAdpcmHwDevice* pHwDevice = CMMFPcm16ToImaAdpcmHwDevice::NewL();
1.1942 + CleanupStack::PushL( pHwDevice );
1.1943 +
1.1944 + CMMFSwCodec& theCodec = pHwDevice->Codec();
1.1945 +
1.1946 + CMMFImaAdpcmToPcm16CodecHwDevice* pHwDecoder = CMMFImaAdpcmToPcm16CodecHwDevice::NewL();
1.1947 + CleanupStack::PushL( pHwDecoder );
1.1948 +
1.1949 + CMMFSwCodec& theDecoder = pHwDecoder->Codec();
1.1950 +
1.1951 + //[ Create data buffers with position != 0]
1.1952 + srcBufferSize = 100; // arbitrary non zero size
1.1953 + sinkBufferSize = 100;
1.1954 + CMMFDescriptorBuffer* pSrcBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.1955 + CleanupStack::PushL( pSrcBuffer );
1.1956 +
1.1957 + CMMFDescriptorBuffer* pSinkBuffer = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.1958 + CleanupStack::PushL( pSinkBuffer );
1.1959 +
1.1960 + //[ trap & check error code ]
1.1961 + TInt errCode;
1.1962 + pSrcBuffer->Data().SetLength(srcBufferSize);
1.1963 + pSinkBuffer->Data().SetLength(sinkBufferSize);
1.1964 + pSrcBuffer->SetPosition(1);
1.1965 + TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
1.1966 + if( errCode != KErrArgument )
1.1967 + {
1.1968 + result = EFail;
1.1969 + return result;
1.1970 + }
1.1971 +
1.1972 + //[set position of sink buffer to nonzero value]
1.1973 + pSrcBuffer->SetPosition(0);
1.1974 + pSinkBuffer->SetPosition(1);
1.1975 + TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
1.1976 + if( errCode != KErrArgument )
1.1977 + {
1.1978 + result = EFail;
1.1979 + return result;
1.1980 + }
1.1981 +
1.1982 + //[set position of sink and src to nonzero value ]
1.1983 + pSrcBuffer->SetPosition(1);
1.1984 + pSinkBuffer->SetPosition(1);
1.1985 + TRAP( errCode, theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer));
1.1986 + if( errCode != KErrArgument )
1.1987 + {
1.1988 + result = EFail;
1.1989 + return result;
1.1990 + }
1.1991 +
1.1992 + //[ reset the position of both buffers to zero ]
1.1993 + pSrcBuffer->SetPosition(0);
1.1994 + pSinkBuffer->SetPosition(0);
1.1995 + //[ set the src/sink buffer sizes to src and sink
1.1996 + // buffer sizes and fill src with data ]
1.1997 + CleanupStack::PopAndDestroy(2, pSrcBuffer); // pSrcBuffer, pSinkBuffer
1.1998 +
1.1999 + //[Create Source & Sink and fill source data in ]
1.2000 + srcBufferSize = theCodec.SourceBufferSize();
1.2001 + pSrcBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.2002 + CleanupStack::PushL( pSrcBuffer );
1.2003 +
1.2004 + CMMFDescriptorBuffer* pDecodedBuffer = CMMFDescriptorBuffer::NewL( srcBufferSize );
1.2005 + CleanupStack::PushL( pDecodedBuffer );
1.2006 +
1.2007 + sinkBufferSize = theCodec.SinkBufferSize();
1.2008 + pSinkBuffer = CMMFDescriptorBuffer::NewL( sinkBufferSize );
1.2009 + CleanupStack::PushL( pSinkBuffer );
1.2010 +
1.2011 + pSrcBuffer->Data().SetLength(srcBufferSize);
1.2012 + pDecodedBuffer->Data().SetLength(srcBufferSize);
1.2013 + pSinkBuffer->Data().SetLength(sinkBufferSize);
1.2014 +
1.2015 + //[ fill src buffer with ramp]
1.2016 + FillSrcBufferL( *pSrcBuffer );
1.2017 + // encode and decode the data
1.2018 + theCodec.ProcessL(*pSrcBuffer, *pSinkBuffer);
1.2019 + theDecoder.ProcessL( *pSinkBuffer, *pDecodedBuffer );
1.2020 +
1.2021 + if(!CompareResults( KExpectedSNRatioDb, pSrcBuffer, pDecodedBuffer))
1.2022 + {
1.2023 + //Test has failed because sn ratio was not good enough
1.2024 + result = EFail;
1.2025 + }
1.2026 +
1.2027 + //[ clean up ]
1.2028 + CleanupStack::PopAndDestroy( 5, pHwDevice ); // pHwDevice, pHwDecoder, pSrcBuffer, pDecodedBuffer, pSinkBuffer
1.2029 +
1.2030 + __MM_HEAP_MARKEND;
1.2031 + return result;
1.2032 + }
1.2033 +
1.2034 +/**
1.2035 +*
1.2036 +* DoTestStepPreambleL
1.2037 +*
1.2038 +**/
1.2039 +TVerdict CTestIMaadCodec::DoTestStepPreambleL(void)
1.2040 + {
1.2041 + return EPass;
1.2042 + }
1.2043 +
1.2044 +/**
1.2045 +*
1.2046 +* DoTestStepPostambleL
1.2047 +*
1.2048 +**/
1.2049 +TVerdict CTestIMaadCodec::DoTestStepPostambleL(void)
1.2050 + {
1.2051 + return EPass;
1.2052 + }
1.2053 +
1.2054 +
1.2055 +/**
1.2056 +*
1.2057 +* FillSrcBuffer
1.2058 +* @param aBuffer
1.2059 +* This function fills the buffer with a ramp of linear pcm16 data
1.2060 +*
1.2061 +**/
1.2062 +void CTestIMaadCodec::FillSrcBufferL( CMMFDescriptorBuffer& aBuffer )
1.2063 + {
1.2064 + TInt slope = 2;
1.2065 + TInt dataLength = aBuffer.Data().Length();
1.2066 + TUint8* pData = const_cast<TUint8*>(aBuffer.Data().Ptr());
1.2067 + TInt noPc16Samples = dataLength/2;
1.2068 + ASSERT( noPc16Samples*slope < 32768 );
1.2069 + for( TInt16 count = 0; count < noPc16Samples ; count++ )
1.2070 + {
1.2071 + TInt16 pcmSample = static_cast<TInt16>( count * slope);
1.2072 + *pData++ = static_cast<TUint8>( pcmSample & 0xFF );
1.2073 + *pData++ = static_cast<TUint8>( ( pcmSample >> 8 ));
1.2074 + }
1.2075 + }
1.2076 +
1.2077 +/**
1.2078 +*
1.2079 +* CompareResults
1.2080 +* @param aExpectedSNRatioDb
1.2081 +* @param aSrcBuffer
1.2082 +* @param aSinkBuffer
1.2083 +* @result TBool
1.2084 +* This function returns True if the computed Signal to Noise Ratio
1.2085 +* is Greater than or equal to the expected signal to noise ratio.
1.2086 +* The function will also return EFalse if any of the preconditions
1.2087 +* are violated.
1.2088 +* @precondition aSrcBuffer, aSinkBuffer are not NULL
1.2089 +* @precondition aSrcBuffer data lenegth == aSinkBuffer data length
1.2090 +* @precondition the data buffers contain pcm16 data
1.2091 +*
1.2092 +**/
1.2093 +TBool CTestIMaadCodec::CompareResults( TReal aExpectedSNRatioDb,
1.2094 + CMMFDescriptorBuffer* aSrcBuffer,
1.2095 + CMMFDescriptorBuffer* aSinkBuffer)
1.2096 + {
1.2097 + TBool result = EFalse;
1.2098 +
1.2099 + //[ precondition pointers are not NULL ]
1.2100 + if( !aSrcBuffer || !aSinkBuffer )
1.2101 + return result;
1.2102 +
1.2103 + //[ precondition buffer lengths are equal ]
1.2104 + TInt length = aSrcBuffer->Data().Length();
1.2105 + if( length != aSinkBuffer->Data().Length() )
1.2106 + return result;
1.2107 +
1.2108 + // buffers must be of even length
1.2109 + if( !(length % sizeof(TInt16) == 0 ))
1.2110 + return result;
1.2111 +
1.2112 + TInt pcmLength = length/2;
1.2113 + TReal sumSignalSquared = 0.0;
1.2114 + TReal sumNoiseSquared = 0.0;
1.2115 + TUint8* pSrcData = const_cast<TUint8*>(aSrcBuffer->Data().Ptr());
1.2116 + TUint8* pDecodeData = const_cast<TUint8*>(aSinkBuffer->Data().Ptr());
1.2117 + TInt16 sampleOriginal;
1.2118 + TInt16 sampleDecode;
1.2119 + for( TInt count = 0; count < pcmLength; count++ )
1.2120 + {
1.2121 + sampleOriginal = static_cast<TInt16>( pSrcData[0] &KAndMask8bit);
1.2122 + sampleOriginal |= static_cast<TInt16>((pSrcData[1] << 8 ));
1.2123 + sampleDecode = static_cast<TInt16>( pDecodeData[0] &KAndMask8bit);
1.2124 + sampleDecode |= static_cast<TInt16>((pDecodeData[1] << 8 ));
1.2125 + pSrcData+=2;
1.2126 + pDecodeData+= 2;
1.2127 + sumSignalSquared += sampleOriginal * sampleOriginal;
1.2128 + TInt noise = sampleOriginal - sampleDecode ;
1.2129 + sumNoiseSquared += noise * noise;
1.2130 + }
1.2131 +
1.2132 + //[ if the noise is low the signals are equivalent and
1.2133 + // overflow can be avoided ]
1.2134 + if( sumNoiseSquared < 0.001 )
1.2135 + {
1.2136 + result = ETrue;
1.2137 + return result;
1.2138 + }
1.2139 + TReal computedSNRatioDb;
1.2140 + Math::Log( computedSNRatioDb, sumSignalSquared/sumNoiseSquared );
1.2141 + computedSNRatioDb *= 10;
1.2142 +
1.2143 + //[ compare claculated s/n ratio against expected ]
1.2144 + if( computedSNRatioDb >= aExpectedSNRatioDb )
1.2145 + result = ETrue;
1.2146 +
1.2147 + return result;
1.2148 + }