os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioMuLawToS16PcmCodec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "MMFAudioMuLawToS16PcmCodec.h"
    17 
    18 /***
    19 *
    20 * Convert
    21 *
    22 */
    23 EXPORT_C void TMMFAudioMuLawToS16PcmCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
    24 	{
    25 	ASSERT(aSrc);
    26 	ASSERT(aDst);
    27 	
    28 	TInt pcm;
    29 	while (aSamples--)
    30 		{
    31 		pcm = MulawSampleToPcm(*aSrc++);
    32 		*aDst++ = STATIC_CAST( TUint8, pcm&KAndMask8bit);
    33 		*aDst++ = STATIC_CAST( TUint8, pcm>>8);
    34 		}
    35 	
    36 	}
    37 
    38 /***
    39 *
    40 * MulawSampleToPcm
    41 * @param aMuLaw
    42 * @return TInt
    43 *
    44 */
    45 TInt TMMFAudioMuLawToS16PcmCodec::MulawSampleToPcm(TUint8 aMulaw)
    46 	{
    47 	TInt sign, exponent, mantissa, sample;
    48 	
    49     aMulaw = STATIC_CAST( TUint8, ~aMulaw);
    50     sign = ( aMulaw & KMaskSign8bit );
    51     exponent = ( aMulaw >> 4 ) & 0x07;
    52     mantissa = aMulaw & 0x0F;
    53     sample = KExpLut[exponent] + ( mantissa << ( exponent + 3 ) );
    54     if ( sign != 0 )
    55 		sample = -sample;
    56 	
    57     return sample;
    58 	}
    59 
    60 const TInt TMMFAudioMuLawToS16PcmCodec::KExpLut[KMdaMulawTo16PcmExpLutSize] = 
    61 	{
    62 	0, 132, 396, 924, 1980, 4092, 8316, 16764
    63 	};