|
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 "MMFAudioSPcm16ToMuLawCodec.h" |
|
17 |
|
18 /*** |
|
19 * |
|
20 * Convert |
|
21 * |
|
22 */ |
|
23 EXPORT_C void TMMFAudioSPcm16ToMuLawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples) |
|
24 { |
|
25 TInt pcm; |
|
26 while (aSamples--) |
|
27 { |
|
28 pcm = (aSrc[0]+(aSrc[1]<<8)); |
|
29 *aDst++ = PcmSampleToMuLaw(STATIC_CAST(TInt16 , pcm)); |
|
30 aSrc+=2; |
|
31 } |
|
32 } |
|
33 |
|
34 //[ conversion look up table pcm16 to Mulaw ] |
|
35 const TInt8 TMMFAudioSPcm16ToMuLawCodec::KExpLut[] = |
|
36 { |
|
37 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, |
|
38 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, |
|
39 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
|
40 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
|
41 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
42 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
43 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
44 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
45 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
46 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
47 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
48 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
49 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
50 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
51 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
52 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
53 }; |
|
54 |
|
55 /*** |
|
56 * |
|
57 * PcmSampleToMulaw |
|
58 * @param Mulaw |
|
59 * @return TUint8 |
|
60 * |
|
61 */ |
|
62 TUint8 TMMFAudioSPcm16ToMuLawCodec::PcmSampleToMuLaw(TInt aPcm) |
|
63 { |
|
64 TInt sign, exponent, mantissa; |
|
65 TUint8 ulawbyte; |
|
66 |
|
67 sign = (aPcm >> 8) & KMaskSign8bit; |
|
68 if ( sign != 0 ) |
|
69 aPcm = STATIC_CAST( TUint16,-aPcm); |
|
70 if ( STATIC_CAST(TUint , aPcm) > STATIC_CAST(TUint , KMda16PcmToMulawClip )) |
|
71 aPcm = KMda16PcmToMulawClip; |
|
72 |
|
73 aPcm = STATIC_CAST(TInt16 , aPcm + KMda16PcmToMulawBias); |
|
74 exponent = KExpLut[( aPcm >> 7 ) & KAndMask8bit]; |
|
75 mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F; |
|
76 ulawbyte = STATIC_CAST( TUint8, ~ ( sign | ( exponent << 4 ) | mantissa )); |
|
77 |
|
78 return ulawbyte; |
|
79 } |