sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // TSU_MMF_CodecTests.cpp sl@0: // sl@0: // sl@0: sl@0: // EPOC includes sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include "TSU_MMF_DeviceSuite.h" sl@0: #include "TSU_MMF_SignConversionCodecs.h" sl@0: sl@0: //[ codec includes ] sl@0: #include sl@0: #include "MmfPcm16toAlawhwDevice.h" sl@0: #include "MmfALawToPcm16HwDevice.h" sl@0: #include "mmfpcm16toMulawhwdevice.h" sl@0: #include "MmfMuLawToPcm16hwDevice.h" sl@0: #include "mmfpcmS8ToPcmS16HwDevice.h" sl@0: #include "mmfpcmS16PcmS8HwDevice.h" sl@0: #include "mmfpcm16topcmU16BEHwDevice.h" sl@0: #include "mmfpcm16SwapEndianhwdevice.h" sl@0: #include "mmfpcm16ToImaAdpcm.h" sl@0: #include "MmfImaAdpcmtopcm16hwdevice.h" sl@0: #include "MMFpcm16ToPcm16HwDevice.h" sl@0: #include "MMFpcm16ToPcmU8HwDevice.h" sl@0: #include "MMFpcmU8ToPcm16HwDevice.h" sl@0: #include "mmfpcmS16PcmS8HwDevice.h" sl@0: sl@0: sl@0: //[ Codec Unit tests structure sl@0: // The unit tests shall use text files sl@0: // for small portions of test data sl@0: // which should be stored are stored in a simple format sl@0: // containing the relevant parameters for the test sl@0: //] sl@0: class TSignConversionTestParams sl@0: { sl@0: public: sl@0: const TText* iTestName; // name of the test sl@0: }; sl@0: sl@0: // constant table of parameters for tests sl@0: const TSignConversionTestParams KSignConversionParameters[] = sl@0: { sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0017-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0018-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0019-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0020-HP")}, sl@0: {_S("MM-MMF-SWCODECDEVICES-U-0021-HP")} sl@0: }; sl@0: sl@0: /** sl@0: * sl@0: * PrintComparisonDataL sl@0: * @param aCodedData the coded data buffer sl@0: * @param aRefCodedData the reference coded data buffer sl@0: * sl@0: */ sl@0: void CMMFDataGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData ) sl@0: { sl@0: //[precondition reference coded data is equal in size or longer than coded data ] sl@0: if( aRefCodedData.Data().Length() < aCodedData.Data().Length() ) sl@0: { sl@0: //[coded data is longer than reference data] sl@0: // RDebug::Print(_L("Coded Data is longer than refernce data")); Commented under DEF105143 sl@0: User::Leave( KErrCorrupt ); sl@0: } sl@0: sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr()); sl@0: TInt length = aCodedData.Data().Length(); sl@0: //[ now print the results for comparison ] sl@0: for( TInt i = 0; i < length; i++ ) sl@0: { sl@0: RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (*ptr1-*ptr2), *ptr1++, *ptr2++ ); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * AssembleValue sl@0: * @param aData src data buffer sl@0: * @param aValue resultant value sl@0: * @param aBigEndian whether the value is in BigEndian format sl@0: * @precondition aData is not null and has length >= 2 sl@0: * sl@0: */ sl@0: void CMMFDataGenerator::AssembleValue( TUint8* aData, TInt16& aValue, TBool aBigEndian ) sl@0: { sl@0: __ASSERT_DEBUG( aData, Panic(EBadArgument)); sl@0: if( aBigEndian ) sl@0: { sl@0: aValue = static_cast( aData[1] &KAndMask8bit ); sl@0: aValue |= static_cast((aData[0] << 8 )); sl@0: } sl@0: else sl@0: { sl@0: aValue = static_cast( aData[0] &KAndMask8bit); sl@0: aValue |= static_cast((aData[1] << 8 )); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * AssembleValue sl@0: * @param aData src data buffer sl@0: * @param aValue resultant value sl@0: * @param aBigEndian whether the value is in BigEndian format sl@0: * @precondition aData is not null and has length >= 2 sl@0: * sl@0: */ sl@0: void CMMFDataGenerator::AssembleValue( TUint8* aData, TUint16& aValue, TBool aBigEndian ) sl@0: { sl@0: __ASSERT_DEBUG( aData, Panic(EBadArgument)); sl@0: if( aBigEndian ) sl@0: { sl@0: aValue = aData[1] ; //[ big endian format] sl@0: aValue |= (aData[0] << 8 ); sl@0: } sl@0: else sl@0: { sl@0: aValue = aData[0] ; sl@0: aValue |= (aData[1] << 8 ); sl@0: } sl@0: } sl@0: /** sl@0: * sl@0: * CMMFPcmU16toPcmU16BGenerator sl@0: * sl@0: **/ sl@0: CMMFPcmU16toPcmU16BGenerator::CMMFPcmU16toPcmU16BGenerator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * ~CMMFPcmU16toPcmU16BGenerator sl@0: * sl@0: **/ sl@0: CMMFPcmU16toPcmU16BGenerator::~CMMFPcmU16toPcmU16BGenerator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateSourceDataL sl@0: * sl@0: **/ sl@0: void CMMFPcmU16toPcmU16BGenerator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TUint16 KScale2 = 32000; sl@0: sl@0: //[ create a buffer large enough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TUint16 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: sl@0: TInt noSamples = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( (KScale2 * val ) + KScale2+0.5); sl@0: *pDst++ = static_cast( srcValue &KAndMask8bit); sl@0: *pDst++ = static_cast( (srcValue >>8) &KAndMask8bit); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateComparisonDataL sl@0: * sl@0: **/ sl@0: void CMMFPcmU16toPcmU16BGenerator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TUint16 KScale2 = 32000; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TUint16 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: sl@0: TInt noSamples = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( (KScale2 * val)+KScale2 +0.5); sl@0: //[endian swap here ] sl@0: *pDst++ = static_cast( (srcValue >>8) &KAndMask8bit); sl@0: *pDst++ = static_cast( srcValue &KAndMask8bit); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * PrintComparisonDataL sl@0: * Prints out coded results for comparison with the sl@0: * Reference values and is used when the results differ sl@0: * sl@0: **/ sl@0: void CMMFPcmU16toPcmU16BGenerator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData ) sl@0: { sl@0: //[precondition reference coded data is equal in size or longer than coded data ] sl@0: if( aRefCodedData.Data().Length() < aCodedData.Data().Length() ) sl@0: { sl@0: //[coded data is longer than reference data] sl@0: // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143 sl@0: User::Leave( KErrCorrupt ); sl@0: } sl@0: sl@0: //[ now print the results for comparison ] sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr()); sl@0: TInt length = aCodedData.Data().Length(); sl@0: length /= 2; // [for 16bit words length is half] sl@0: //[ assert invariant length is even ] sl@0: __ASSERT_DEBUG( (length % 2 == 0 ), Panic(EBadInvariant)); sl@0: sl@0: TUint16 codedValue = 0; sl@0: TUint16 refCodedValue = 0; sl@0: //[ now print the results for comparison ] sl@0: for( TInt i = 0; i < length; i++ ) sl@0: { sl@0: //[ assemble 16bit values from buffer values ] sl@0: AssembleValue( ptr1, codedValue, ETrue ); sl@0: AssembleValue( ptr2, refCodedValue, ETrue ); sl@0: RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue ); sl@0: if( i % 100 == 0 ) //deal with debug printf deficiencies sl@0: { sl@0: User::After(100 ); sl@0: } sl@0: ptr1+=2; sl@0: ptr2+=2; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CMMFPcmU16BtoPcmU16Generator sl@0: * sl@0: **/ sl@0: CMMFPcmU16BtoPcmU16Generator::CMMFPcmU16BtoPcmU16Generator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * ~CMMFPcmU16BtoPcmU16Generator sl@0: * sl@0: **/ sl@0: CMMFPcmU16BtoPcmU16Generator::~CMMFPcmU16BtoPcmU16Generator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateSourceDataL sl@0: * sl@0: **/ sl@0: void CMMFPcmU16BtoPcmU16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TUint8 KScale2 = 127; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TInt8 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: sl@0: TInt noSamples = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( (KScale2 * val) ); sl@0: //[endian swap here ] sl@0: *pDst++ = static_cast( (srcValue >>8) &KAndMask8bit); sl@0: *pDst++ = static_cast( srcValue &KAndMask8bit); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateComparisonDataL sl@0: * sl@0: **/ sl@0: void CMMFPcmU16BtoPcmU16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TUint8 KScale2 = 127; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TUint16 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TInt noSamples = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( KScale2 * val ); sl@0: *pDst++ = static_cast( srcValue &KAndMask8bit); sl@0: *pDst++ = static_cast( (srcValue >>8) &KAndMask8bit); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * PrintComparisonDataL sl@0: * Prints out coded results for comparison with the sl@0: * Reference values and is used when the results differ sl@0: * sl@0: **/ sl@0: void CMMFPcmU16BtoPcmU16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData ) sl@0: { sl@0: //[precondition reference coded data is equal in size or longer than coded data ] sl@0: if( aRefCodedData.Data().Length() < aCodedData.Data().Length() ) sl@0: { sl@0: //[coded data is longer than reference data] sl@0: // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143 sl@0: User::Leave( KErrCorrupt ); sl@0: } sl@0: sl@0: //[ now print the results for comparison ] sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr()); sl@0: TInt length = aCodedData.Data().Length(); sl@0: length /= 2; //[ for 16bit words ] sl@0: TUint16 codedValue = 0; sl@0: TUint16 refCodedValue = 0; sl@0: //[ now print the results for comparison ] sl@0: for( TInt i = 0; i < length; i++ ) sl@0: { sl@0: // assemble 16bit values sl@0: AssembleValue( ptr1, codedValue, EFalse); sl@0: AssembleValue( ptr2, refCodedValue, EFalse ); sl@0: RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (refCodedValue-codedValue), codedValue, refCodedValue ); sl@0: if( i % 100 == 0 ) //deal with debug printf deficiencies sl@0: { sl@0: User::After( 100 ); sl@0: } sl@0: ptr1+=2; sl@0: ptr2+=2; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CMMFPcm8ToPcm16Generator sl@0: * sl@0: **/ sl@0: CMMFPcm8ToPcm16Generator::CMMFPcm8ToPcm16Generator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CMMFPcm8ToPcm16Generator sl@0: * sl@0: **/ sl@0: CMMFPcm8ToPcm16Generator::~CMMFPcm8ToPcm16Generator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateSourceDataL sl@0: * sl@0: **/ sl@0: void CMMFPcm8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TInt8 KScale2 = 127; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TInt8 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TInt noSamples = aSize/sizeof(TInt8); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( (KScale2 * val) ); sl@0: *pDst++ = srcValue; sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateSourceDataL sl@0: * sl@0: **/ sl@0: void CMMFPcm8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TInt8 KScale2 = 127; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TInt16 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TInt noSamples = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: TInt8 temp = static_cast((KScale2 * val)); sl@0: srcValue = static_cast( temp << 8); sl@0: *pDst++ = static_cast( srcValue&KAndMask8bit); sl@0: *pDst++ = static_cast((srcValue>>8)&KAndMask8bit); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * PrintComparisonDataL sl@0: * Prints out coded results for comparison with the sl@0: * Reference values and is used when the results differ sl@0: * sl@0: **/ sl@0: void CMMFPcm8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData ) sl@0: { sl@0: //[precondition reference coded data is equal in size or longer than coded data ] sl@0: if( aRefCodedData.Data().Length() < aCodedData.Data().Length() ) sl@0: { sl@0: //[coded data is longer than reference data] sl@0: // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143 sl@0: User::Leave( KErrCorrupt ); sl@0: } sl@0: sl@0: //[ now print the results for comparison ] sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr()); sl@0: TInt length = aCodedData.Data().Length(); sl@0: length /= 2; //[ for 16bit words ] sl@0: TInt16 codedValue = 0; sl@0: TInt16 refCodedValue = 0; sl@0: //[ now print the results for comparison ] sl@0: for( TInt i = 0; i < length; i++ ) sl@0: { sl@0: // assemble 16bit values sl@0: AssembleValue( ptr1, codedValue, EFalse ); sl@0: AssembleValue( ptr2, refCodedValue, EFalse ); sl@0: RDebug::Print( _L("difference: %d, coded: %d, RefCoded: %d"), (refCodedValue-codedValue), codedValue, refCodedValue ); sl@0: if( i % 100 == 0 ) //deal with debug printf deficiencies sl@0: { sl@0: User::After(100 ); sl@0: } sl@0: ptr1+=2; sl@0: ptr2+=2; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CMMFPcmU8ToPcm16Generator sl@0: * sl@0: **/ sl@0: CMMFPcmU8ToPcm16Generator::CMMFPcmU8ToPcm16Generator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * ~CMMFPcmU8ToPcm16Generator sl@0: * sl@0: **/ sl@0: CMMFPcmU8ToPcm16Generator::~CMMFPcmU8ToPcm16Generator() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateSourceDataL sl@0: * @param aBuffer sl@0: * @param aSize in bytes sl@0: * sl@0: **/ sl@0: void CMMFPcmU8ToPcm16Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TUint8 KScale2 = 127; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TUint8 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TInt noSamples = aSize/sizeof(TUint8); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: sl@0: srcValue = static_cast((KScale2 * val+KScale2+0.5)); sl@0: *pDst++ = srcValue; sl@0: //RDebug::Print( _L("U8 = %u"), srcValue ); Statement commented under DEf105143 sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateComparisonDataL sl@0: * @param aBuffer sl@0: * @param aSize sl@0: * sl@0: **/ sl@0: void CMMFPcmU8ToPcm16Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TInt8 KScale2 = 127; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: // RDebug::Print( _L("Generation"));Commented under DEF105143 sl@0: TUint8 theValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TUint8 rrr = 0; sl@0: TInt length = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< length; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = KPi*i/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: theValue = static_cast(KScale2 *val + KScale2 + 0.5); sl@0: //[ apply the same transformation as the codec ] sl@0: rrr = static_cast( theValue^KMaskSign8bit ); sl@0: //RDebug::Print( _L("U8 = %u"), theValue ); Statement commented under DEf105143 sl@0: *pDst++ = rrr; sl@0: *pDst++ = rrr; sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * PrintComparisonDataL sl@0: * Prints out coded results for comparison with the sl@0: * Reference values and is used when the results differ sl@0: * sl@0: **/ sl@0: void CMMFPcmU8ToPcm16Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData ) sl@0: { sl@0: //[precondition reference coded data is equal in size or longer than coded data ] sl@0: if( aRefCodedData.Data().Length() < aCodedData.Data().Length() ) sl@0: { sl@0: //[coded data is longer than reference data] sl@0: // RDebug::Print( _L("Coded Data is longer than reference data"));Commented under DEF105143 sl@0: User::Leave( KErrCorrupt ); sl@0: } sl@0: sl@0: //[ now print the results for comparison ] sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr()); sl@0: TInt length = aCodedData.Data().Length(); sl@0: length /= 2; //[ for 16bit words ] sl@0: TInt16 codedValue = 0; sl@0: TInt16 refCodedValue = 0; sl@0: //[ now print the results for comparison ] sl@0: for( TInt i = 0; i < length; i++ ) sl@0: { sl@0: // assemble 16bit values sl@0: AssembleValue( ptr1, codedValue, EFalse ); sl@0: AssembleValue( ptr2, refCodedValue, EFalse ); sl@0: RDebug::Print( _L("delta %d c %d, rf %d"), (refCodedValue-codedValue), codedValue, refCodedValue ); sl@0: if( i % 100 == 0 ) //deal with debug printf deficiencies sl@0: { sl@0: User::After(100 ); sl@0: } sl@0: ptr1+=2; sl@0: ptr2+=2; sl@0: } sl@0: sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CMMFPcm16ToPcmU8Generator sl@0: * sl@0: **/ sl@0: CMMFPcm16ToPcmU8Generator::CMMFPcm16ToPcmU8Generator() sl@0: { sl@0: //Nothing doing sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CMMFPcm16ToPcmU8Generator sl@0: * sl@0: **/ sl@0: CMMFPcm16ToPcmU8Generator::~CMMFPcm16ToPcmU8Generator() sl@0: { sl@0: //Nothing doing sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateSourceDataL sl@0: * @param aBuffer sl@0: * @param aSize in bytes sl@0: * This function generates a 400hz sine wav sl@0: * under the assumption the sampling frequency is 8khz sl@0: * sl@0: */ sl@0: void CMMFPcm16ToPcmU8Generator::GenerateSourceDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TInt KScale = 320; sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TInt16 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TInt noSamples = aSize/sizeof(TInt16); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( KScale * val ); sl@0: *pDst++ = static_cast( srcValue & KAndMask8bit); sl@0: *pDst++ = static_cast((srcValue >> 8) & KAndMask8bit ); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * GenerateComparisonDataL sl@0: * @param aBuffer sl@0: * @param aSize in bytes sl@0: * This function generates a 400hz sine wav sl@0: * under the assumption the sampling frequency is 8khz sl@0: */ sl@0: //[ use partial sopecialization to provide copncrete implmentation] sl@0: void CMMFPcm16ToPcmU8Generator::GenerateComparisonDataL( CMMFDataBuffer* &aBuffer, TInt aSize ) sl@0: { sl@0: const TInt KScale2 = 320; //low value chosen to emphasize the distortion of this codec! sl@0: sl@0: //[ create a buffer large eneough to fill with the data ] sl@0: aBuffer = CMMFDescriptorBuffer::NewL(aSize); sl@0: sl@0: TUint8* pDst = CONST_CAST(TUint8*,aBuffer->Data().Ptr()); sl@0: sl@0: //[ lets fill it with a 400hz signal at approx -3db ] sl@0: //[encode the data] sl@0: TInt16 srcValue = 0; sl@0: TReal val = 0.0; sl@0: TReal theta = 0.0; sl@0: TInt noSamples = aSize/sizeof(TUint8); sl@0: for(TInt i=0; i< noSamples; i++) sl@0: { sl@0: //[ assign data and place in buffer] sl@0: theta = (KPi*i)/10; // fundamental of 400hz sampled @8khz has 20 db or sl@0: // better reproduction through gsm codec sl@0: User::LeaveIfError(Math::Sin(val,theta)); sl@0: srcValue = static_cast( KScale2 * val ); sl@0: *pDst++ = static_cast( (srcValue >> 8) - KMaskSign8bit); sl@0: } sl@0: sl@0: aBuffer->Data().SetLength(aSize); sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * PrintComparisonDataL sl@0: * Prints out coded results for comparison with the sl@0: * Reference values and is used when the results differ sl@0: * sl@0: **/ sl@0: void CMMFPcm16ToPcmU8Generator::PrintComparisonDataL( CMMFDataBuffer& aCodedData, CMMFDataBuffer& aRefCodedData ) sl@0: { sl@0: //[precondition reference coded data is equal in size or longer than coded data ] sl@0: if( aRefCodedData.Data().Length() < aCodedData.Data().Length() ) sl@0: { sl@0: //[coded data is longer than reference data] sl@0: // RDebug::Print( _L("Coded Data is longer than refernce data"));Commented under DEF105143 sl@0: User::Leave( KErrCorrupt ); sl@0: } sl@0: sl@0: //[ now print the results for comparison ] sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aCodedData.Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aRefCodedData.Data().Ptr()); sl@0: TInt length = aCodedData.Data().Length(); sl@0: //[ now print the results for comparison ] sl@0: for( TInt i = 0; i < length; i++ ) sl@0: { sl@0: RDebug::Print( _L("difference: %u, coded: %u, RefCoded: %u"), (*ptr1-*ptr2), *ptr1, *ptr2 ); sl@0: if( i % 100 == 0 ) //deal with debug printf deficiencies sl@0: { sl@0: User::After(100 ); sl@0: } sl@0: ptr1++; sl@0: ptr2++; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CompareData sl@0: * @param aData1 first data buffer for comparison sl@0: * @param aData2 second data buffer for comparison sl@0: * result TBool data is the same sl@0: * @precondition aData1 has the same amount of data as aData2 sl@0: * sl@0: */ sl@0: template sl@0: TBool CTestStepSignConversionTest::CompareData( CMMFDataBuffer* aData1, CMMFDataBuffer* aData2) sl@0: { sl@0: TBool result = ETrue; sl@0: sl@0: //[ precondition aData1 != NULL ] sl@0: if( !aData1 ) sl@0: { sl@0: User::Leave( KErrArgument ); sl@0: } sl@0: sl@0: //[ precondition aData2 != NULL ] sl@0: if( !aData2 ) sl@0: { sl@0: User::Leave( KErrArgument ); sl@0: } sl@0: sl@0: //[precondition aData1 length == aData2 length ] sl@0: if( aData1->Data().Length() != aData2->Data().Length() ) sl@0: { sl@0: User::Leave( KErrArgument ); sl@0: } sl@0: sl@0: //[Now Compare the data] sl@0: TUint8* ptr1 = CONST_CAST(TUint8*, aData1->Data().Ptr()); sl@0: TUint8* ptr2 = CONST_CAST(TUint8*, aData2->Data().Ptr()); sl@0: TInt dataLength = aData2->Data().Length(); sl@0: if( Mem::Compare( ptr1, dataLength, ptr2, dataLength )!=0) sl@0: { sl@0: TUint8* p1 = ptr1; sl@0: TUint8* p2 = ptr2; sl@0: TInt16 s1 = 0; sl@0: TInt16 s2 = 0; sl@0: INFO_PRINTF1(_L("------------------------------")); sl@0: for( TInt i = 0; i < dataLength/2; i++ ) sl@0: { sl@0: s1 = static_cast( p1[0] &KAndMask8bit); sl@0: s1 |= static_cast((p1[1] << 8 )); sl@0: s2 = static_cast( p2[0] &KAndMask8bit); sl@0: s2 |= static_cast((p2[1] << 8 )); sl@0: INFO_PRINTF3(_L("%d %d"), s1, s2); sl@0: p1+=2; sl@0: p2+=2; sl@0: } sl@0: INFO_PRINTF1(_L("------------------------------")); sl@0: // RDebug::Print( _L("Comparison has failed")); Commented under DEF105143 sl@0: iGenerator->PrintComparisonDataL( *aData1, *aData2 ); sl@0: result = EFalse ; sl@0: } sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoTestStepL sl@0: * @result TVerdict sl@0: * sl@0: */ sl@0: template sl@0: TVerdict CTestStepSignConversionTest::DoTestStepL() sl@0: { sl@0: __MM_HEAP_MARK; sl@0: TVerdict result = EPass; sl@0: sl@0: //[pre condition iSourceData ] sl@0: if( !iSourceData ) sl@0: { sl@0: INFO_PRINTF1(_L("Source Data Failure")); sl@0: User::Leave( KErrCorrupt); sl@0: } sl@0: //[precondition iCodedData ] sl@0: if( !iCodedData ) sl@0: { sl@0: INFO_PRINTF1(_L("Coded Data Failure")); sl@0: User::Leave( KErrCorrupt); sl@0: } sl@0: //[precondition iRefData ] sl@0: if( !iRefCodedData ) sl@0: { sl@0: INFO_PRINTF1(_L("RefCodedData Argument Failure")); sl@0: User::Leave( KErrCorrupt); sl@0: } sl@0: sl@0: //[ lets code the data and compare it to the reference data ] sl@0: iCodecUnderTest->ProcessL(*iSourceData, *iCodedData); sl@0: if(!CompareData(iCodedData, iRefCodedData)) sl@0: { sl@0: INFO_PRINTF1(_L("Coded Results do not match reference coded results")); sl@0: sl@0: result = EFail; sl@0: } sl@0: sl@0: __MM_HEAP_MARKEND; sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoTestStepPostambleL sl@0: * @result TVerdict sl@0: * sl@0: */ sl@0: template sl@0: TVerdict CTestStepSignConversionTest::DoTestStepPostambleL() sl@0: { sl@0: TVerdict result = EPass; sl@0: //[delete the buffers & Codec] sl@0: delete iCodecUnderTest; sl@0: delete iGenerator; sl@0: delete iSourceData; sl@0: delete iCodedData; sl@0: delete iRefCodedData; sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * DoTestStepPreambleL sl@0: * @result TVerdict sl@0: * sl@0: */ sl@0: template sl@0: TVerdict CTestStepSignConversionTest::DoTestStepPreambleL() sl@0: { sl@0: TVerdict result = EPass; sl@0: sl@0: iCodecUnderTest = new(ELeave) T; // a cmmfcodec ; sl@0: iGenerator = new(ELeave) Generator; // src generator sl@0: sl@0: //[ensure the number of samples is >= srcbuffers] sl@0: const TInt KNumBuffers = 2; sl@0: const TInt dataSrcSize = KNumBuffers * iCodecUnderTest->SourceBufferSize(); sl@0: sl@0: //[generate src data] sl@0: iGenerator->GenerateSourceDataL( iSourceData, dataSrcSize); sl@0: sl@0: const TInt dataSinkSize = KNumBuffers * iCodecUnderTest->SinkBufferSize(); sl@0: sl@0: //[generate comparison data] sl@0: iGenerator->GenerateComparisonDataL( iRefCodedData, dataSinkSize); sl@0: sl@0: //[reserve space for coded data ] sl@0: iCodedData = CMMFDescriptorBuffer::NewL(dataSinkSize); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CTestStepCodecUnitTest sl@0: * sl@0: */ sl@0: template sl@0: CTestStepSignConversionTest::CTestStepSignConversionTest() sl@0: { sl@0: // store the name of this test case sl@0: // this is the name that is used by the script file sl@0: iTestStepName = (&KSignConversionParameters[index])->iTestName; sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * CTestStepCodecUnitTest sl@0: * sl@0: */ sl@0: template sl@0: CTestStepSignConversionTest::~CTestStepSignConversionTest() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * sl@0: * This is used for template instantiation. sl@0: * sl@0: **/ sl@0: sl@0: template class CTestStepSignConversionTest; sl@0: template class CTestStepSignConversionTest; sl@0: template class CTestStepSignConversionTest; sl@0: template class CTestStepSignConversionTest; sl@0: template class CTestStepSignConversionTest; sl@0: