|
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 "MMFAudioSPcm16ToALawCodec.h" |
|
17 |
|
18 /*** |
|
19 * |
|
20 * Convert |
|
21 * |
|
22 */ |
|
23 EXPORT_C void TMMFAudioSPcm16ToAlawCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples) |
|
24 { |
|
25 TInt16* pcm = (TInt16*)aSrc; |
|
26 TInt16* pcmLimit = pcm + aSamples; |
|
27 |
|
28 while (pcm < pcmLimit) |
|
29 { |
|
30 *aDst++ = PcmSampleToAlaw(*pcm++); |
|
31 } |
|
32 |
|
33 } |
|
34 |
|
35 //[ conversion look up table pcm16 to alaw ] |
|
36 const TInt8 TMMFAudioSPcm16ToAlawCodec::KExpLut[] = |
|
37 { |
|
38 1,1,2,2,3,3,3,3, |
|
39 4,4,4,4,4,4,4,4, |
|
40 5,5,5,5,5,5,5,5, |
|
41 5,5,5,5,5,5,5,5, |
|
42 6,6,6,6,6,6,6,6, |
|
43 6,6,6,6,6,6,6,6, |
|
44 6,6,6,6,6,6,6,6, |
|
45 6,6,6,6,6,6,6,6, |
|
46 7,7,7,7,7,7,7,7, |
|
47 7,7,7,7,7,7,7,7, |
|
48 7,7,7,7,7,7,7,7, |
|
49 7,7,7,7,7,7,7,7, |
|
50 7,7,7,7,7,7,7,7, |
|
51 7,7,7,7,7,7,7,7, |
|
52 7,7,7,7,7,7,7,7, |
|
53 7,7,7,7,7,7,7,7 |
|
54 }; |
|
55 |
|
56 /*** |
|
57 * |
|
58 * PcmSampleToAlaw |
|
59 * @param aLaw |
|
60 * @return TUint8 |
|
61 * |
|
62 */ |
|
63 TUint8 TMMFAudioSPcm16ToAlawCodec::PcmSampleToAlaw(TInt aPcm) |
|
64 { |
|
65 TInt sign; |
|
66 TInt exponent; |
|
67 TInt mantissa; |
|
68 TUint8 alawbyte; |
|
69 |
|
70 sign = ((~aPcm) >> 8) & KMaskSign8bit; |
|
71 if (sign == 0) |
|
72 aPcm = -aPcm; |
|
73 if (aPcm > KMda16PcmToAlawClip) |
|
74 aPcm = KMda16PcmToAlawClip; |
|
75 |
|
76 if (aPcm >= 256) |
|
77 { |
|
78 exponent = KExpLut[( aPcm >> 8 ) & 0x7F]; |
|
79 mantissa = ( aPcm >> ( exponent + 3 ) ) & 0x0F; |
|
80 alawbyte = STATIC_CAST( TUint8, (( exponent << 4 ) | mantissa)); |
|
81 } |
|
82 else |
|
83 alawbyte = STATIC_CAST( TUint8, aPcm >> 4); |
|
84 |
|
85 alawbyte ^= (sign ^ 0x55); |
|
86 |
|
87 return alawbyte; |
|
88 } |
|
89 |