⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkerror.cpp

📁 这是G.723和G.729的音频编解码的源代码
💻 CPP
字号:
// CheckError.cpp: implementation of the CCheckError class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "VideoComm.h"
#include "CheckError.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//crctab calculated by Mark G. Mendel, Network Systems Corporation
extern unsigned short crc16tab[256];//define zmodem.cpp

#define UPDCRC16(cp, crc) (crc16tab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCheckError::CCheckError()
{

}

CCheckError::~CCheckError()
{

}

void CCheckError::CaculateCRC(BYTE *pbyIn, int nInLength, BYTE *pbyOut, int* nOutLength)
{
	int nOld = 0;

	if(nInLength <= 0) return;
	ASSERT(pbyIn != NULL);
	ASSERT(pbyOut != NULL);

	unsigned short crc = 0;

	while (nOld < nInLength) {//caculate crc
		crc = UPDCRC16(pbyIn[nOld],crc);
		nOld++;
	}

	if(pbyOut != pbyIn)
		::memcpy(pbyOut, pbyIn, nInLength);
	pbyOut[nInLength] = (unsigned char)(crc >> 8);
	pbyOut[nInLength + 1] = (unsigned char)crc;

	*nOutLength = nInLength + 2;
}

BOOL CCheckError::IsDataRigth(BYTE *pData, int nLength, BYTE *pOutData, int* nOutLength)
{
	if(nLength <= 0) return TRUE;
	ASSERT(pData != NULL);

	unsigned short crc = 0;
	unsigned short ReceiveCRC = 0;
	int nDataLength = nLength - 2;//last 2 byte is crc16
	int l = 0;

	while (l < nDataLength) {//caculate crc
		crc = UPDCRC16(pData[l],crc);
		l++;
	}
	ReceiveCRC = (pData[nDataLength] << 8) | pData[nDataLength + 1];
	if(crc == ReceiveCRC)//right crc
	{
		if(pData != pOutData)//not same variable
			::memcpy(pOutData, pData, nDataLength);
		*nOutLength = nDataLength;
		return TRUE;
	}
	else
		return FALSE;
}

⌨️ 快捷键说明

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