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