1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioSPcm16ToMuLawCodec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,79 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "MMFAudioSPcm16ToMuLawCodec.h"
1.20 +
1.21 +/***
1.22 +*
1.23 +* Convert
1.24 +*
1.25 +*/
1.26 +EXPORT_C void TMMFAudioSPcm16ToMuLawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
1.27 + {
1.28 + TInt pcm;
1.29 + while (aSamples--)
1.30 + {
1.31 + pcm = (aSrc[0]+(aSrc[1]<<8));
1.32 + *aDst++ = PcmSampleToMuLaw(STATIC_CAST(TInt16 , pcm));
1.33 + aSrc+=2;
1.34 + }
1.35 + }
1.36 +
1.37 +//[ conversion look up table pcm16 to Mulaw ]
1.38 +const TInt8 TMMFAudioSPcm16ToMuLawCodec::KExpLut[] =
1.39 + {
1.40 + 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
1.41 + 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
1.42 + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1.43 + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
1.44 + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.45 + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.46 + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.47 + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
1.48 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.49 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.50 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.51 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.52 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.53 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.54 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1.55 + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
1.56 + };
1.57 +
1.58 +/***
1.59 +*
1.60 +* PcmSampleToMulaw
1.61 +* @param Mulaw
1.62 +* @return TUint8
1.63 +*
1.64 +*/
1.65 +TUint8 TMMFAudioSPcm16ToMuLawCodec::PcmSampleToMuLaw(TInt aPcm)
1.66 + {
1.67 + TInt sign, exponent, mantissa;
1.68 + TUint8 ulawbyte;
1.69 +
1.70 + sign = (aPcm >> 8) & KMaskSign8bit;
1.71 + if ( sign != 0 )
1.72 + aPcm = STATIC_CAST( TUint16,-aPcm);
1.73 + if ( STATIC_CAST(TUint , aPcm) > STATIC_CAST(TUint , KMda16PcmToMulawClip ))
1.74 + aPcm = KMda16PcmToMulawClip;
1.75 +
1.76 + aPcm = STATIC_CAST(TInt16 , aPcm + KMda16PcmToMulawBias);
1.77 + exponent = KExpLut[( aPcm >> 7 ) & KAndMask8bit];
1.78 + mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F;
1.79 + ulawbyte = STATIC_CAST( TUint8, ~ ( sign | ( exponent << 4 ) | mantissa ));
1.80 +
1.81 + return ulawbyte;
1.82 + }