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 |
// MMFAudioImaAdpcmToS16PcmCodec.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "MMFAudioImaAdpcmToS16PcmCodec.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
*
|
sl@0
|
22 |
* Convert
|
sl@0
|
23 |
* @param aSrc
|
sl@0
|
24 |
* @param aDst
|
sl@0
|
25 |
* @param aSamples
|
sl@0
|
26 |
*
|
sl@0
|
27 |
*/
|
sl@0
|
28 |
EXPORT_C void TMMFAudioImaAdpcmToS16PcmCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
|
sl@0
|
29 |
{
|
sl@0
|
30 |
TInt delta; // Current adpcm output value
|
sl@0
|
31 |
TInt step; // Stepsize
|
sl@0
|
32 |
TInt valpred; // Predicted value
|
sl@0
|
33 |
TInt vpdiff; // Current change to valpred
|
sl@0
|
34 |
TInt index; // Current step change index
|
sl@0
|
35 |
|
sl@0
|
36 |
//[Read first sample and index from block header
|
sl@0
|
37 |
// we do not need to store the information across calls
|
sl@0
|
38 |
//since we process the entire block here]
|
sl@0
|
39 |
valpred = (*aSrc++) & KAndMask8bit;
|
sl@0
|
40 |
valpred |= STATIC_CAST(TInt16, ((*aSrc++) << 8));
|
sl@0
|
41 |
index = *aSrc++;
|
sl@0
|
42 |
TUint8* dst=aDst;
|
sl@0
|
43 |
|
sl@0
|
44 |
aSrc++; //skip reserved header byte
|
sl@0
|
45 |
|
sl@0
|
46 |
//Write first sample to dest
|
sl@0
|
47 |
*aDst++ = STATIC_CAST( TUint8, valpred);
|
sl@0
|
48 |
*aDst++ = STATIC_CAST( TUint8, valpred >> 8);
|
sl@0
|
49 |
dst += 2;
|
sl@0
|
50 |
aSamples --;
|
sl@0
|
51 |
|
sl@0
|
52 |
TBool theBufferStep = ETrue;
|
sl@0
|
53 |
TInt bufferValue = 0;
|
sl@0
|
54 |
for ( ; aSamples > 0 ; aSamples-- )
|
sl@0
|
55 |
{
|
sl@0
|
56 |
// Step 1 - get the delta value
|
sl@0
|
57 |
if ( theBufferStep)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
bufferValue = *aSrc++;
|
sl@0
|
60 |
delta = bufferValue & 0xf;
|
sl@0
|
61 |
}
|
sl@0
|
62 |
else
|
sl@0
|
63 |
{
|
sl@0
|
64 |
delta = (bufferValue >> 4) & 0xf;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
theBufferStep = !theBufferStep;
|
sl@0
|
68 |
|
sl@0
|
69 |
ASSERT(index >= 0);
|
sl@0
|
70 |
step = KStepSizeTable[index];
|
sl@0
|
71 |
|
sl@0
|
72 |
vpdiff = step>>3;
|
sl@0
|
73 |
if ( delta & 4 )
|
sl@0
|
74 |
vpdiff += step;
|
sl@0
|
75 |
if ( delta & 2 )
|
sl@0
|
76 |
vpdiff += step>>1;
|
sl@0
|
77 |
if ( delta & 1 )
|
sl@0
|
78 |
vpdiff += step>>2;
|
sl@0
|
79 |
|
sl@0
|
80 |
if ( delta & 8 )
|
sl@0
|
81 |
valpred -= vpdiff;
|
sl@0
|
82 |
else
|
sl@0
|
83 |
valpred += vpdiff;
|
sl@0
|
84 |
|
sl@0
|
85 |
if ( valpred > (KClamp - 1) )
|
sl@0
|
86 |
valpred = (KClamp - 1);
|
sl@0
|
87 |
else if ( valpred < -KClamp )
|
sl@0
|
88 |
valpred = -KClamp;
|
sl@0
|
89 |
|
sl@0
|
90 |
index += KIndexTable[delta];
|
sl@0
|
91 |
if ( index < 0 )
|
sl@0
|
92 |
index = 0;
|
sl@0
|
93 |
if ( index > KMaxImaAdpcmTableEntries )
|
sl@0
|
94 |
index = KMaxImaAdpcmTableEntries;
|
sl@0
|
95 |
|
sl@0
|
96 |
*dst++ = STATIC_CAST( TUint8, valpred&KAndMask8bit);
|
sl@0
|
97 |
*dst++ = STATIC_CAST( TUint8, (valpred>>8) );
|
sl@0
|
98 |
}
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
// IMA-ADPCM step variation table
|
sl@0
|
104 |
const TInt TMMFAudioImaAdpcmToS16PcmCodec::KIndexTable[] =
|
sl@0
|
105 |
{
|
sl@0
|
106 |
-1, -1, -1, -1, 2, 4, 6, 8,
|
sl@0
|
107 |
-1, -1, -1, -1, 2, 4, 6, 8
|
sl@0
|
108 |
};
|
sl@0
|
109 |
|
sl@0
|
110 |
const TInt TMMFAudioImaAdpcmToS16PcmCodec::KStepSizeTable[89] =
|
sl@0
|
111 |
{
|
sl@0
|
112 |
7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
|
sl@0
|
113 |
19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
|
sl@0
|
114 |
50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
|
sl@0
|
115 |
130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
|
sl@0
|
116 |
337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
|
sl@0
|
117 |
876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
|
sl@0
|
118 |
2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
|
sl@0
|
119 |
5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
|
sl@0
|
120 |
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
|
sl@0
|
121 |
};
|