sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "MMFAudioSPcm16ToALawCodec.h" sl@0: sl@0: /*** sl@0: * sl@0: * Convert sl@0: * sl@0: */ sl@0: EXPORT_C void TMMFAudioSPcm16ToAlawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples) sl@0: { sl@0: TInt16* pcm = (TInt16*)aSrc; sl@0: TInt16* pcmLimit = pcm + aSamples; sl@0: sl@0: while (pcm < pcmLimit) sl@0: { sl@0: *aDst++ = PcmSampleToAlaw(*pcm++); sl@0: } sl@0: sl@0: } sl@0: sl@0: //[ conversion look up table pcm16 to alaw ] sl@0: const TInt8 TMMFAudioSPcm16ToAlawCodec::KExpLut[] = sl@0: { sl@0: 1,1,2,2,3,3,3,3, sl@0: 4,4,4,4,4,4,4,4, sl@0: 5,5,5,5,5,5,5,5, sl@0: 5,5,5,5,5,5,5,5, sl@0: 6,6,6,6,6,6,6,6, sl@0: 6,6,6,6,6,6,6,6, sl@0: 6,6,6,6,6,6,6,6, sl@0: 6,6,6,6,6,6,6,6, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7, sl@0: 7,7,7,7,7,7,7,7 sl@0: }; sl@0: sl@0: /*** sl@0: * sl@0: * PcmSampleToAlaw sl@0: * @param aLaw sl@0: * @return TUint8 sl@0: * sl@0: */ sl@0: TUint8 TMMFAudioSPcm16ToAlawCodec::PcmSampleToAlaw(TInt aPcm) sl@0: { sl@0: TInt sign; sl@0: TInt exponent; sl@0: TInt mantissa; sl@0: TUint8 alawbyte; sl@0: sl@0: sign = ((~aPcm) >> 8) & KMaskSign8bit; sl@0: if (sign == 0) sl@0: aPcm = -aPcm; sl@0: if (aPcm > KMda16PcmToAlawClip) sl@0: aPcm = KMda16PcmToAlawClip; sl@0: sl@0: if (aPcm >= 256) sl@0: { sl@0: exponent = KExpLut[( aPcm >> 8 ) & 0x7F]; sl@0: mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F; sl@0: alawbyte = STATIC_CAST( TUint8, (( exponent << 4 ) | mantissa)); sl@0: } sl@0: else sl@0: alawbyte = STATIC_CAST( TUint8, aPcm >> 4); sl@0: sl@0: alawbyte ^= (sign ^ 0x55); sl@0: sl@0: return alawbyte; sl@0: } sl@0: