os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioSPcm16ToALawCodec.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "MMFAudioSPcm16ToALawCodec.h"
sl@0
    17
sl@0
    18
/***
sl@0
    19
*
sl@0
    20
* Convert
sl@0
    21
*
sl@0
    22
*/
sl@0
    23
EXPORT_C void TMMFAudioSPcm16ToAlawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
sl@0
    24
	{
sl@0
    25
	TInt16* pcm = (TInt16*)aSrc;
sl@0
    26
	TInt16* pcmLimit = pcm + aSamples; 
sl@0
    27
sl@0
    28
	while (pcm < pcmLimit)
sl@0
    29
		{
sl@0
    30
		*aDst++ = PcmSampleToAlaw(*pcm++);
sl@0
    31
		}
sl@0
    32
sl@0
    33
	}
sl@0
    34
sl@0
    35
//[ conversion look up table pcm16 to alaw ]
sl@0
    36
const TInt8 TMMFAudioSPcm16ToAlawCodec::KExpLut[] = 
sl@0
    37
	{
sl@0
    38
	1,1,2,2,3,3,3,3,
sl@0
    39
	4,4,4,4,4,4,4,4,
sl@0
    40
	5,5,5,5,5,5,5,5,
sl@0
    41
	5,5,5,5,5,5,5,5,
sl@0
    42
	6,6,6,6,6,6,6,6,
sl@0
    43
	6,6,6,6,6,6,6,6,
sl@0
    44
	6,6,6,6,6,6,6,6,
sl@0
    45
	6,6,6,6,6,6,6,6,
sl@0
    46
	7,7,7,7,7,7,7,7,
sl@0
    47
	7,7,7,7,7,7,7,7,
sl@0
    48
	7,7,7,7,7,7,7,7,
sl@0
    49
	7,7,7,7,7,7,7,7,
sl@0
    50
	7,7,7,7,7,7,7,7,
sl@0
    51
	7,7,7,7,7,7,7,7,
sl@0
    52
	7,7,7,7,7,7,7,7,
sl@0
    53
	7,7,7,7,7,7,7,7
sl@0
    54
	};
sl@0
    55
sl@0
    56
/***
sl@0
    57
*
sl@0
    58
* PcmSampleToAlaw
sl@0
    59
* @param aLaw
sl@0
    60
* @return TUint8
sl@0
    61
*
sl@0
    62
*/
sl@0
    63
TUint8 TMMFAudioSPcm16ToAlawCodec::PcmSampleToAlaw(TInt aPcm)
sl@0
    64
	{
sl@0
    65
    TInt sign;
sl@0
    66
	TInt exponent;
sl@0
    67
	TInt mantissa;
sl@0
    68
	TUint8 alawbyte;
sl@0
    69
sl@0
    70
    sign = ((~aPcm) >> 8) & KMaskSign8bit;		
sl@0
    71
    if (sign == 0)
sl@0
    72
		aPcm = -aPcm;	
sl@0
    73
    if (aPcm > KMda16PcmToAlawClip) 
sl@0
    74
		aPcm = KMda16PcmToAlawClip;
sl@0
    75
sl@0
    76
    if (aPcm >= 256)
sl@0
    77
		{
sl@0
    78
		exponent = KExpLut[( aPcm >> 8 ) & 0x7F];
sl@0
    79
		mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F;
sl@0
    80
		alawbyte = STATIC_CAST( TUint8, (( exponent << 4 ) | mantissa));
sl@0
    81
		}
sl@0
    82
    else
sl@0
    83
		alawbyte = STATIC_CAST( TUint8, aPcm >> 4);
sl@0
    84
sl@0
    85
    alawbyte ^= (sign ^ 0x55);
sl@0
    86
sl@0
    87
    return alawbyte;
sl@0
    88
	}
sl@0
    89