First public contribution.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "MMFAudioSPcm16ToMuLawCodec.h"
23 EXPORT_C void TMMFAudioSPcm16ToMuLawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
28 pcm = (aSrc[0]+(aSrc[1]<<8));
29 *aDst++ = PcmSampleToMuLaw(STATIC_CAST(TInt16 , pcm));
34 //[ conversion look up table pcm16 to Mulaw ]
35 const TInt8 TMMFAudioSPcm16ToMuLawCodec::KExpLut[] =
37 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
38 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
39 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
40 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
41 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
42 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
43 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
44 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
45 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
46 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
47 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
48 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
49 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
50 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
51 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
52 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
62 TUint8 TMMFAudioSPcm16ToMuLawCodec::PcmSampleToMuLaw(TInt aPcm)
64 TInt sign, exponent, mantissa;
67 sign = (aPcm >> 8) & KMaskSign8bit;
69 aPcm = STATIC_CAST( TUint16,-aPcm);
70 if ( STATIC_CAST(TUint , aPcm) > STATIC_CAST(TUint , KMda16PcmToMulawClip ))
71 aPcm = KMda16PcmToMulawClip;
73 aPcm = STATIC_CAST(TInt16 , aPcm + KMda16PcmToMulawBias);
74 exponent = KExpLut[( aPcm >> 7 ) & KAndMask8bit];
75 mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F;
76 ulawbyte = STATIC_CAST( TUint8, ~ ( sign | ( exponent << 4 ) | mantissa ));