mulawencoder.cpp

来自「symbian下ffmpeg编程。。废了好大劲下下来的!。」· C++ 代码 · 共 55 行

CPP
55
字号
#include "mulawencoder.h"/* * Based on example code from http://hazelware.luggle.com/tutorials/mulawcompression.html */static const TInt KMuLawBias = 0x84;static const TInt KMuLawClip = 32635;static const TUint8 KMuLawCompressTable[] = {	 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,	 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,	 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,	 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,	 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,	 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,	 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,	 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,	 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};static TUint8 ToMuLaw(TInt16 aSample) {	TInt sign = (aSample >> 8) & 0x80;	if (sign)		aSample = (TInt16) -(aSample + 1); // the +1 is for handling the case when aSample == -32768	if (aSample > KMuLawClip)		aSample = KMuLawClip;	aSample += KMuLawBias;	TInt exponent = KMuLawCompressTable[(aSample >> 7) & 0xFF];	TInt mantissa = (aSample >> (exponent + 3)) & 0x0F;	TUint8 compressedByte = ~ (sign | (exponent << 4) | mantissa);	return compressedByte;}TInt CMuLawEncoder::Encode(const TDesC8& aBuffer, TUint8* aOutBuffer) {	const TInt16* ptr = reinterpret_cast<const TInt16*>(aBuffer.Ptr());	TInt len = aBuffer.Length()/2;	for (TInt i = 0; i < len; i++) {		*aOutBuffer = ToMuLaw(*ptr);		ptr++;		aOutBuffer++;	}	return len;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?