os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioALawToPcm16Codec.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioALawToPcm16Codec.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,70 @@
     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 "MMFAudioALawToS16PcmCodec.h"
    1.20 +
    1.21 +/***
    1.22 +*
    1.23 +* Convert
    1.24 +*
    1.25 +*/
    1.26 +EXPORT_C void TMMFAudioALawToS16PcmCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
    1.27 +	{
    1.28 +	ASSERT(aSrc);
    1.29 +	ASSERT(aDst);
    1.30 +	
    1.31 +	TInt pcm;
    1.32 +	while (aSamples--)
    1.33 +		{
    1.34 +		pcm = AlawSampleToPcm(*aSrc++);
    1.35 +		*aDst++ = STATIC_CAST( TUint8, pcm&KAndMask8bit);
    1.36 +		*aDst++ = STATIC_CAST( TUint8, pcm>>8);
    1.37 +		}
    1.38 +	
    1.39 +	}
    1.40 +
    1.41 +/***
    1.42 +*
    1.43 +* AlawSampleToPcm
    1.44 +* @param aLaw
    1.45 +* @return TInt
    1.46 +*
    1.47 +*/
    1.48 +TInt TMMFAudioALawToS16PcmCodec::AlawSampleToPcm(TUint8 aAlaw)
    1.49 +	{
    1.50 +    TInt sign, exponent, mantissa, sample;
    1.51 +	
    1.52 +    aAlaw ^= 0x55;	//will leave this as is, more readable
    1.53 +    sign = ( aAlaw & KMaskSign8bit );
    1.54 +    aAlaw &= 0x7f;			/* get magnitude */
    1.55 +    if (aAlaw >= 16)
    1.56 +		{
    1.57 +		exponent = (aAlaw >> 4 ) & 0x07;
    1.58 +		mantissa = aAlaw & 0x0F;
    1.59 +		sample = KExpLut[exponent] + ( mantissa << ( exponent + 3 ) );
    1.60 +		}
    1.61 +    else
    1.62 +		sample = (aAlaw << 4) + 8;
    1.63 +	
    1.64 +    if ( sign == 0 )
    1.65 +		sample = -sample;
    1.66 +	
    1.67 +    return sample;
    1.68 +	}
    1.69 +
    1.70 +const TInt TMMFAudioALawToS16PcmCodec::KExpLut[] = 
    1.71 +	{
    1.72 +	0, 264, 528, 1056, 2112, 4224, 8448, 16896
    1.73 +	};