|
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 "MMFAudioALawToS16PcmCodec.h" |
|
17 |
|
18 /*** |
|
19 * |
|
20 * Convert |
|
21 * |
|
22 */ |
|
23 EXPORT_C void TMMFAudioALawToS16PcmCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples) |
|
24 { |
|
25 ASSERT(aSrc); |
|
26 ASSERT(aDst); |
|
27 |
|
28 TInt pcm; |
|
29 while (aSamples--) |
|
30 { |
|
31 pcm = AlawSampleToPcm(*aSrc++); |
|
32 *aDst++ = STATIC_CAST( TUint8, pcm&KAndMask8bit); |
|
33 *aDst++ = STATIC_CAST( TUint8, pcm>>8); |
|
34 } |
|
35 |
|
36 } |
|
37 |
|
38 /*** |
|
39 * |
|
40 * AlawSampleToPcm |
|
41 * @param aLaw |
|
42 * @return TInt |
|
43 * |
|
44 */ |
|
45 TInt TMMFAudioALawToS16PcmCodec::AlawSampleToPcm(TUint8 aAlaw) |
|
46 { |
|
47 TInt sign, exponent, mantissa, sample; |
|
48 |
|
49 aAlaw ^= 0x55; //will leave this as is, more readable |
|
50 sign = ( aAlaw & KMaskSign8bit ); |
|
51 aAlaw &= 0x7f; /* get magnitude */ |
|
52 if (aAlaw >= 16) |
|
53 { |
|
54 exponent = (aAlaw >> 4 ) & 0x07; |
|
55 mantissa = aAlaw & 0x0F; |
|
56 sample = KExpLut[exponent] + ( mantissa << ( exponent + 3 ) ); |
|
57 } |
|
58 else |
|
59 sample = (aAlaw << 4) + 8; |
|
60 |
|
61 if ( sign == 0 ) |
|
62 sample = -sample; |
|
63 |
|
64 return sample; |
|
65 } |
|
66 |
|
67 const TInt TMMFAudioALawToS16PcmCodec::KExpLut[] = |
|
68 { |
|
69 0, 264, 528, 1056, 2112, 4224, 8448, 16896 |
|
70 }; |