1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioSPcm16ToALawCodec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,89 @@
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 "MMFAudioSPcm16ToALawCodec.h"
1.20 +
1.21 +/***
1.22 +*
1.23 +* Convert
1.24 +*
1.25 +*/
1.26 +EXPORT_C void TMMFAudioSPcm16ToAlawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
1.27 + {
1.28 + TInt16* pcm = (TInt16*)aSrc;
1.29 + TInt16* pcmLimit = pcm + aSamples;
1.30 +
1.31 + while (pcm < pcmLimit)
1.32 + {
1.33 + *aDst++ = PcmSampleToAlaw(*pcm++);
1.34 + }
1.35 +
1.36 + }
1.37 +
1.38 +//[ conversion look up table pcm16 to alaw ]
1.39 +const TInt8 TMMFAudioSPcm16ToAlawCodec::KExpLut[] =
1.40 + {
1.41 + 1,1,2,2,3,3,3,3,
1.42 + 4,4,4,4,4,4,4,4,
1.43 + 5,5,5,5,5,5,5,5,
1.44 + 5,5,5,5,5,5,5,5,
1.45 + 6,6,6,6,6,6,6,6,
1.46 + 6,6,6,6,6,6,6,6,
1.47 + 6,6,6,6,6,6,6,6,
1.48 + 6,6,6,6,6,6,6,6,
1.49 + 7,7,7,7,7,7,7,7,
1.50 + 7,7,7,7,7,7,7,7,
1.51 + 7,7,7,7,7,7,7,7,
1.52 + 7,7,7,7,7,7,7,7,
1.53 + 7,7,7,7,7,7,7,7,
1.54 + 7,7,7,7,7,7,7,7,
1.55 + 7,7,7,7,7,7,7,7,
1.56 + 7,7,7,7,7,7,7,7
1.57 + };
1.58 +
1.59 +/***
1.60 +*
1.61 +* PcmSampleToAlaw
1.62 +* @param aLaw
1.63 +* @return TUint8
1.64 +*
1.65 +*/
1.66 +TUint8 TMMFAudioSPcm16ToAlawCodec::PcmSampleToAlaw(TInt aPcm)
1.67 + {
1.68 + TInt sign;
1.69 + TInt exponent;
1.70 + TInt mantissa;
1.71 + TUint8 alawbyte;
1.72 +
1.73 + sign = ((~aPcm) >> 8) & KMaskSign8bit;
1.74 + if (sign == 0)
1.75 + aPcm = -aPcm;
1.76 + if (aPcm > KMda16PcmToAlawClip)
1.77 + aPcm = KMda16PcmToAlawClip;
1.78 +
1.79 + if (aPcm >= 256)
1.80 + {
1.81 + exponent = KExpLut[( aPcm >> 8 ) & 0x7F];
1.82 + mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F;
1.83 + alawbyte = STATIC_CAST( TUint8, (( exponent << 4 ) | mantissa));
1.84 + }
1.85 + else
1.86 + alawbyte = STATIC_CAST( TUint8, aPcm >> 4);
1.87 +
1.88 + alawbyte ^= (sign ^ 0x55);
1.89 +
1.90 + return alawbyte;
1.91 + }
1.92 +