4
#define KPackedFrameLen 10
5
#define KUnpackedFrameLen 22
7
// Below values are taken from the APS design document
8
const TUint8 KG729FullPayloadBits[] = { 8, 10, 8, 1, 13, 4, 7, 5, 13, 4, 7 };
9
const TUint KNumFullFrameParams = 11;
10
const TUint8 KG729SIDPayloadBits[] = { 1, 5, 4, 5 };
11
const TUint KNumSIDFrameParams = 4;
16
@discussion Provides compression from 16-bit-word-aligned G.729 audio frames
17
(used in S60 G.729 DSP codec) to 8-bit stream, and vice versa.
25
@discussion Constructor
27
TBitStream():iDes(iData,KUnpackedFrameLen){}
29
@function CompressG729Frame
31
@discussion Compress either a 22-byte G.729 full rate frame to 10 bytes
32
or a 8-byte G.729 Annex.B SID frame to 2 bytes.
33
@param aSrc Reference to the uncompressed source frame data
34
@param aIsSIDFrame True if the source is a SID frame
35
@result a reference to the compressed frame
37
const TDesC8& CompressG729Frame( const TDesC8& aSrc, TBool aIsSIDFrame = EFalse );
40
@function ExpandG729Frame
42
@discussion Expand a 10-byte G.729 full rate frame to 22 bytes
43
or a 2-byte G.729 Annex.B SID frame to 8(22) bytes.
44
@param aSrc Reference to the compressed source frame data
45
@param aIsSIDFrame True if the source is a SID frame
46
@result a reference to a descriptor representing the uncompressed frame.
47
Note that SID frames are zero-padded to 22 bytes as well.
49
const TDesC8& ExpandG729Frame( const TDesC8& aSrc, TBool aIsSIDFrame = EFalse );
52
void Compress( TUint8 aValue, TUint8 aNumOfBits );
53
void Expand( const TUint8* aSrc, TInt aDstIdx, TUint8 aNumOfBits );
56
TUint8 iData[KUnpackedFrameLen];
63
const TDesC8& TBitStream::CompressG729Frame( const TDesC8& aSrc, TBool aIsSIDFrame )
66
iDes.FillZ(iDes.MaxLength());
67
iIdx = iBitOffset = 0;
69
TInt numParams = (aIsSIDFrame) ? KNumSIDFrameParams : KNumFullFrameParams;
70
const TUint8* p = const_cast<TUint8*>(aSrc.Ptr());
72
for(TInt i = 0, pIdx = 0; i < numParams; i++, pIdx += 2)
74
TUint8 paramBits = (aIsSIDFrame) ? KG729SIDPayloadBits[i] : KG729FullPayloadBits[i];
77
Compress(p[pIdx+1], paramBits - 8); // msb
80
Compress(p[pIdx], paramBits); // lsb
91
const TDesC8& TBitStream::ExpandG729Frame( const TDesC8& aSrc, TBool aIsSIDFrame )
94
iDes.FillZ(iDes.MaxLength());
95
iIdx = iBitOffset = 0;
97
TInt numParams = (aIsSIDFrame) ? KNumSIDFrameParams : KNumFullFrameParams;
98
const TUint8* p = const_cast<TUint8*>(aSrc.Ptr());
100
for(TInt i = 0, dIdx = 0; i < numParams; i++, dIdx += 2)
102
TUint8 paramBits = (aIsSIDFrame) ? KG729SIDPayloadBits[i] : KG729FullPayloadBits[i];
105
Expand(p, dIdx+1, paramBits - 8); // msb
108
Expand(p, dIdx, paramBits); // lsb
111
iDes.SetLength(KUnpackedFrameLen);
116
void TBitStream::Compress( TUint8 aValue, TUint8 aNumOfBits )
118
// clear bits that will be discarded
119
aValue &= (0xff >> (8 - aNumOfBits));
121
// calculate required bitwise left shift
122
TInt shl = 8 - (iBitOffset + aNumOfBits);
124
if (shl == 0) // no shift required
126
iData[iIdx++] |= aValue;
129
else if (shl > 0) // bits fit into current byte
131
iData[iIdx] |= (aValue << shl);
132
iBitOffset += aNumOfBits;
137
iData[iIdx] |= (aValue >> iBitOffset); // right shift
138
iData[++iIdx] |= (aValue << (8-iBitOffset)); // push remaining bits to next byte
143
void TBitStream::Expand( const TUint8* aSrc, TInt aDstIdx, TUint8 aNumOfBits )
145
TUint8 aValue = aSrc[iIdx] & (0xff >> iBitOffset);
147
// calculate required bitwise right shift
148
TInt shr = 8 - (iBitOffset + aNumOfBits);
150
if (shr == 0) // no shift required
152
iData[aDstIdx] = aValue;
156
else if (shr > 0) // right shift
158
iData[aDstIdx] = (aValue >> shr);
159
iBitOffset += aNumOfBits;
161
else // shift left and take remaining bits from the next src byte
164
iData[aDstIdx] = aValue << iBitOffset;
165
iData[aDstIdx] |= aSrc[++iIdx] >> (8 - iBitOffset);
169
#endif // __BITSTREAM_H_