?? mframe.c
字號:
/*
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2003-2006 Intel Corporation. All Rights Reserved.
//
// Intel(R) Integrated Performance Primitives Aurora Sample for Windows*
//
// By downloading and installing this sample, you hereby agree that the
// accompanying Materials are being provided to you under the terms and
// conditions of the End User License Agreement for the Intel(R) Integrated
// Performance Primitives product previously accepted by you. Please refer
// to the file ippEULA.rtf located in the root directory of your Intel(R) IPP
// product installation for more information.
//
// ES 201 108 v1.1.3 is the international standard promoted by ETSI
// and other organizations. Implementations of these standards, or the standard
// enabled platforms may require licenses from various entities, including
// Intel Corporation.
//
*/
#include "mframe.h"
#include <stdio.h>
#include <math.h>
void madeHeader(MFrame *pFrame,int mframeCounter){
unsigned short int crc, data;
unsigned char sync[2]={0xb2,0x87};
pFrame->pFrameBuffer[0] = sync[0];
pFrame->pFrameBuffer[1] = sync[1];
data = 0x0003 & pFrame->sampRate;
data |= 0x0078 & (mframeCounter<<3);
crc = calcCRC(data);
pFrame->pFrameBuffer[2] = 0xff & data;
pFrame->pFrameBuffer[3] = 0xff & (data >> 8);
pFrame->pFrameBuffer[4] = 0xff & crc ;
pFrame->pFrameBuffer[5] = 0xff & (crc >> 8);
return;
}
unsigned short calcCRC(unsigned short data){
unsigned short pMask[16] = {0x808b,0xc0ce,0xe0ed,0x7077,0xb8b0,0x5c58,0x2e2c,
0x1716,0x8b01,0x4581,0x22c1,0x1161,0x08b1,0x0459,0x022d,0x0117};
int i;
unsigned short mask;
unsigned short crc=0;
for (i=0,mask=0x1; i<16; i++,mask<<=1)
if (mask & data)
crc ^= pMask[i];
return crc;
}
unsigned char encodeCRC(unsigned char *data){
int i;
unsigned char crcBuff[16] = {0,13,3,14,6,11,5,8,12,1,15,2,10,7,9,4};
unsigned char crc,idx;
crc = 0;
for (i=0; i<22; i++){
idx = (i % 2 == 0) ? (0xf & data[i / 2]) : ((0xf0 & data[i / 2]) >> 4);
crc = crcBuff[crc ^ idx];
}
return crc;
}
int CheckFrames(unsigned char *pIndexVQBuffer,unsigned char *pCRCBuffer,short crc){
int iCountFoundZero;
int FrameNoZero;
int j;
FrameNoZero = 2;
if(encodeCRC(pCRCBuffer)!=crc){
printf("Warning: A CRC error detected in multiframe \n");
iCountFoundZero = 0;
for(j=0; j<7; j++)
if(pIndexVQBuffer[j]==0) iCountFoundZero++;
if(iCountFoundZero>=5)
FrameNoZero=0;
else{
FrameNoZero = 0;
for(j=7; j<14; j++)
if(pIndexVQBuffer[j]==0) iCountFoundZero++;
if(iCountFoundZero>=5)
FrameNoZero=1;
else
FrameNoZero=2;
}
FrameNoZero |= 0x4;
}
else{
iCountFoundZero = 0;
for(j=0; j<7; j++)
if(pIndexVQBuffer[j]==0) iCountFoundZero++;
if(iCountFoundZero==7)
FrameNoZero=0;
else{
iCountFoundZero = 0;
for(j=7; j<14; j++)
if(pIndexVQBuffer[j]==0) iCountFoundZero++;
if(iCountFoundZero==7)
FrameNoZero=1;
else
FrameNoZero=2;
}
}
return FrameNoZero;
}
int CheckThreshold_16s(short *pPrev){
int error,i;
short treshold_16s[14] = {7,6,5,5,4,4,4,4,4,3,3,3,16,2};
short diff[14];
for (i=0; i<14; i++)
diff[i]=(short)fabs(pPrev[i]-pPrev[i+16]);
error = 0;
for (i=0;i<14;i+=2)
if((diff[i] > treshold_16s[i]) || (diff[i+1] > treshold_16s[i+1])) error++;
if(error >= 2){
printf("Warning:Threshold error(s) in multiframe");
return 1;
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -