1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/sounddevbt/src/Plugin/Codec/SBCEncoder/BtSBCEncoder.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,182 @@
1.4 +// Copyright (c) 2005-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 +//
1.18 +
1.19 +#ifndef __BTSBCENCODER_H__
1.20 +#define __BTSBCENCODER_H__
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <mmf/server/mmfcodec.h>
1.24 +
1.25 +#include "BtSBCFrameParameters.h"
1.26 +
1.27 +const TUint8 KSbcMaxBlocks = 16;
1.28 +const TUint8 KSbcMaxChannels = 2;
1.29 +const TUint8 KSbcMaxSubbands = 8;
1.30 +
1.31 +/**
1.32 +This class is for manipulating (reading/writing) raw bit stream.
1.33 +It is used in sbc encoder for generating sbc frame bit stream.
1.34 +@internalComponent
1.35 +*/
1.36 +class CBitStreamParser : public CBase
1.37 + {
1.38 +public:
1.39 + static CBitStreamParser* NewLC(TDes8& aBitStream);
1.40 + void Reset();
1.41 +
1.42 + /** relative position */
1.43 + TUint8 ReadBits(TInt aBitsToRead);
1.44 + void WriteBits(TInt aBitsToWrite, TUint8 aBitsValue);
1.45 +
1.46 + inline TUint8 ReadByte();
1.47 + inline void WriteByte(TUint8 aByteValue);
1.48 +
1.49 + /** absolute position */
1.50 + inline void SetPosition(TUint aByteOffset, TUint8 aBitOffset);
1.51 + inline void Position(TUint& aByteOffset, TUint8& aBitOffset) const;
1.52 +
1.53 +private:
1.54 + CBitStreamParser(TDes8& aBitStream);
1.55 + ~CBitStreamParser();
1.56 +
1.57 + void ConstructL();
1.58 +
1.59 +private:
1.60 + TDes8& iBitStream;
1.61 + TUint8* iPtr;
1.62 + TUint iByteOffset;
1.63 + TUint8 iBitOffset;
1.64 + };
1.65 +
1.66 +/**
1.67 +This class is for checking and generating SBC CRC code.
1.68 +It is used in sbc encoder for generating SBC CRC check number.
1.69 +@internalComponent
1.70 +*/
1.71 +class CSbcCRCCalculator : public CBase
1.72 + {
1.73 +public:
1.74 + CSbcCRCCalculator();
1.75 +
1.76 + void Reset();
1.77 + void InputBit(TUint8 aBit);
1.78 + void InputBits(TUint8 aBits, TUint8 aValue);
1.79 + void InputByte(TUint8 aByte);
1.80 +
1.81 + TUint8 ShiftRegister();
1.82 +
1.83 +private:
1.84 + TUint8 iShiftRegister;
1.85 + };
1.86 +
1.87 +/**
1.88 +This class is for encoding one SBC frame
1.89 +@internalComponent
1.90 +*/
1.91 +class CSBCFrameEncoder : public CBase
1.92 + {
1.93 +public:
1.94 + static CSBCFrameEncoder* NewL();
1.95 + ~CSBCFrameEncoder();
1.96 + void EncodeFrameL(const TDesC8& aSrc, TDes8& aFrame);
1.97 + void Configure(const TSBCFrameParameters& aParameters);
1.98 + void Reset();
1.99 +
1.100 +private:
1.101 + CSBCFrameEncoder();
1.102 + void ConstructL();
1.103 +
1.104 + /** encode frame */
1.105 + void Analyse(const TDesC8& aSrc);
1.106 + void CalcScaleFactors();
1.107 + void JoinSubbands();
1.108 + void CalcBitAllocation();
1.109 + void Quantize();
1.110 +
1.111 + void AnalyseMono(const TInt16 aInputSamples[]);
1.112 + void AnalyseOneChannel(const TInt16 aInputSamples[], TUint8 aChannel);
1.113 + void Analyse4Subbands(const TInt16 aInputSamples[], TUint8 aBlock, TUint8 aChannel);
1.114 + void Analyse8Subbands(const TInt16 aInputSamples[], TUint8 aBlock, TUint8 aChannel);
1.115 +
1.116 + void DoJoinSubbands();
1.117 +
1.118 + void CalcBitAllocIndependent();
1.119 + void CalcBitneedIndependent(TInt8 aBitneed[], const TUint8 aScaleFactors[]);
1.120 + TInt8 MaxBitneedIndependent(const TInt8 aBitneed[]);
1.121 + TInt8 CalcBitSlicesIndependent(const TInt8 aBitneed[], TInt& aBitCount);
1.122 + void DistributeBitsIndependent(const TInt8 aBitneed[], TUint8 aBits[]);
1.123 +
1.124 + void CalcBitAllocCombined();
1.125 + void CalcBitneedCombined(TInt8 aBitneed[][KSbcMaxSubbands]);
1.126 + TInt8 MaxBitneedCombined(const TInt8 aBitneed[][KSbcMaxSubbands]);
1.127 + TInt8 CalcBitSlicesCombined(const TInt8 aBitneed[][KSbcMaxSubbands], TInt& aBitCount);
1.128 + void DistributeBitsCombined(const TInt8 aBitneed[][KSbcMaxSubbands]);
1.129 +
1.130 + TUint8 CalcCRC();
1.131 +
1.132 + /** writing result back */
1.133 + void WriteFrameL(TDes8& aFrame);
1.134 + void WriteHeader(CBitStreamParser& aParser);
1.135 + void WriteScaleFactors(CBitStreamParser& aParser);
1.136 + void WriteData(CBitStreamParser& aParser);
1.137 + void WritePaddingL(CBitStreamParser& aParser);
1.138 +
1.139 +private:
1.140 + /** input parameters, set before encode */
1.141 + TSBCFrameParameters iParameters;
1.142 +
1.143 + TInt16 iAnalysisSamples[2][KSbcMaxSubbands * 10];
1.144 + TUint8 iScaleFactors[2][KSbcMaxSubbands];
1.145 + TUint8 iBits[2][KSbcMaxSubbands];
1.146 + TInt32 iOutputSamples[KSbcMaxBlocks][2][KSbcMaxSubbands];
1.147 + TUint8 iJoin[KSbcMaxSubbands];
1.148 + };
1.149 +
1.150 +/**
1.151 +This class is for encoding one SBC frame
1.152 +@internalComponent
1.153 +*/
1.154 +class CSBCEncoder : public CMMFCodec
1.155 + {
1.156 +public:
1.157 + static CMMFCodec* NewL(TAny* aInitParams);
1.158 + virtual ~CSBCEncoder();
1.159 + void ConfigureL(TUid aConfigType, const TDesC8& aConfigData);
1.160 + TCodecProcessResult ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst);
1.161 +
1.162 +private:
1.163 + CSBCEncoder();
1.164 + void ConstructL(TAny* aInitParams);
1.165 + void ResetL();
1.166 +
1.167 + TUint EncodeFrameL(const TDesC8& aSrc, TDes8& aDst);
1.168 + TUint CachePcmSamplesL(const CMMFDataBuffer& aSrc, TUint aSrcPos);
1.169 + TUint CachedSampleSize();
1.170 +
1.171 +private:
1.172 + /** input parameters, set before encode */
1.173 + TSBCFrameParameters iParameters;
1.174 + TUint iPcmFrameSize;
1.175 +
1.176 + /** CSBCFrameEncoder encodes each frame */
1.177 + CSBCFrameEncoder* iSbcFrameEncoder;
1.178 + TUint iSbcFrameLength;
1.179 +
1.180 + /** pcm audio sample cach */
1.181 + HBufC8* iPcmSampleCach;
1.182 + };
1.183 +
1.184 +#endif // __BTSBCENCODER_H__
1.185 +