1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/Codecs/Src/MMFCodecCommon/MMFAudioImaAdpcmToS16Codec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,121 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// MMFAudioImaAdpcmToS16PcmCodec.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "MMFAudioImaAdpcmToS16PcmCodec.h"
1.22 +
1.23 +/**
1.24 +*
1.25 +* Convert
1.26 +* @param aSrc
1.27 +* @param aDst
1.28 +* @param aSamples
1.29 +*
1.30 +*/
1.31 +EXPORT_C void TMMFAudioImaAdpcmToS16PcmCodec::Convert(TUint8* aSrc, TUint8* aDst, TInt aSamples)
1.32 + {
1.33 + TInt delta; // Current adpcm output value
1.34 + TInt step; // Stepsize
1.35 + TInt valpred; // Predicted value
1.36 + TInt vpdiff; // Current change to valpred
1.37 + TInt index; // Current step change index
1.38 +
1.39 + //[Read first sample and index from block header
1.40 + // we do not need to store the information across calls
1.41 + //since we process the entire block here]
1.42 + valpred = (*aSrc++) & KAndMask8bit;
1.43 + valpred |= STATIC_CAST(TInt16, ((*aSrc++) << 8));
1.44 + index = *aSrc++;
1.45 + TUint8* dst=aDst;
1.46 +
1.47 + aSrc++; //skip reserved header byte
1.48 +
1.49 + //Write first sample to dest
1.50 + *aDst++ = STATIC_CAST( TUint8, valpred);
1.51 + *aDst++ = STATIC_CAST( TUint8, valpred >> 8);
1.52 + dst += 2;
1.53 + aSamples --;
1.54 +
1.55 + TBool theBufferStep = ETrue;
1.56 + TInt bufferValue = 0;
1.57 + for ( ; aSamples > 0 ; aSamples-- )
1.58 + {
1.59 + // Step 1 - get the delta value
1.60 + if ( theBufferStep)
1.61 + {
1.62 + bufferValue = *aSrc++;
1.63 + delta = bufferValue & 0xf;
1.64 + }
1.65 + else
1.66 + {
1.67 + delta = (bufferValue >> 4) & 0xf;
1.68 + }
1.69 +
1.70 + theBufferStep = !theBufferStep;
1.71 +
1.72 + ASSERT(index >= 0);
1.73 + step = KStepSizeTable[index];
1.74 +
1.75 + vpdiff = step>>3;
1.76 + if ( delta & 4 )
1.77 + vpdiff += step;
1.78 + if ( delta & 2 )
1.79 + vpdiff += step>>1;
1.80 + if ( delta & 1 )
1.81 + vpdiff += step>>2;
1.82 +
1.83 + if ( delta & 8 )
1.84 + valpred -= vpdiff;
1.85 + else
1.86 + valpred += vpdiff;
1.87 +
1.88 + if ( valpred > (KClamp - 1) )
1.89 + valpred = (KClamp - 1);
1.90 + else if ( valpred < -KClamp )
1.91 + valpred = -KClamp;
1.92 +
1.93 + index += KIndexTable[delta];
1.94 + if ( index < 0 )
1.95 + index = 0;
1.96 + if ( index > KMaxImaAdpcmTableEntries )
1.97 + index = KMaxImaAdpcmTableEntries;
1.98 +
1.99 + *dst++ = STATIC_CAST( TUint8, valpred&KAndMask8bit);
1.100 + *dst++ = STATIC_CAST( TUint8, (valpred>>8) );
1.101 + }
1.102 + }
1.103 +
1.104 +
1.105 +
1.106 +// IMA-ADPCM step variation table
1.107 +const TInt TMMFAudioImaAdpcmToS16PcmCodec::KIndexTable[] =
1.108 + {
1.109 + -1, -1, -1, -1, 2, 4, 6, 8,
1.110 + -1, -1, -1, -1, 2, 4, 6, 8
1.111 + };
1.112 +
1.113 +const TInt TMMFAudioImaAdpcmToS16PcmCodec::KStepSizeTable[89] =
1.114 + {
1.115 + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
1.116 + 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
1.117 + 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
1.118 + 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
1.119 + 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
1.120 + 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
1.121 + 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
1.122 + 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
1.123 + 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
1.124 + };