Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // MMFAudioImaAdpcmToS16PcmCodec.cpp
18 #include "MMFAudioImaAdpcmToS16PcmCodec.h"
28 EXPORT_C void TMMFAudioImaAdpcmToS16PcmCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
30 TInt delta; // Current adpcm output value
31 TInt step; // Stepsize
32 TInt valpred; // Predicted value
33 TInt vpdiff; // Current change to valpred
34 TInt index; // Current step change index
36 //[Read first sample and index from block header
37 // we do not need to store the information across calls
38 //since we process the entire block here]
39 valpred = (*aSrc++) & KAndMask8bit;
40 valpred |= STATIC_CAST(TInt16, ((*aSrc++) << 8));
44 aSrc++; //skip reserved header byte
46 //Write first sample to dest
47 *aDst++ = STATIC_CAST( TUint8, valpred);
48 *aDst++ = STATIC_CAST( TUint8, valpred >> 8);
52 TBool theBufferStep = ETrue;
54 for ( ; aSamples > 0 ; aSamples-- )
56 // Step 1 - get the delta value
59 bufferValue = *aSrc++;
60 delta = bufferValue & 0xf;
64 delta = (bufferValue >> 4) & 0xf;
67 theBufferStep = !theBufferStep;
70 step = KStepSizeTable[index];
85 if ( valpred > (KClamp - 1) )
86 valpred = (KClamp - 1);
87 else if ( valpred < -KClamp )
90 index += KIndexTable[delta];
93 if ( index > KMaxImaAdpcmTableEntries )
94 index = KMaxImaAdpcmTableEntries;
96 *dst++ = STATIC_CAST( TUint8, valpred&KAndMask8bit);
97 *dst++ = STATIC_CAST( TUint8, (valpred>>8) );
103 // IMA-ADPCM step variation table
104 const TInt TMMFAudioImaAdpcmToS16PcmCodec::KIndexTable[] =
106 -1, -1, -1, -1, 2, 4, 6, 8,
107 -1, -1, -1, -1, 2, 4, 6, 8
110 const TInt TMMFAudioImaAdpcmToS16PcmCodec::KStepSizeTable[89] =
112 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
113 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
114 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
115 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
116 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
117 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
118 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
119 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
120 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767