void I2sAnalyzer::SetupForGettingFirstFrame() { GetNextBit( mLastData, mLastFrame, mLastSample ); //we have to throw away one bit to get enough history on the FRAME line. for( ; ; ) { GetNextBit( mCurrentData, mCurrentFrame, mCurrentSample ); if( mCurrentFrame == BIT_HIGH && mLastFrame == BIT_LOW ) { if( mSettings->mBitAlignment == BITS_SHIFTED_RIGHT_1 ) { //we need to advance to the next bit past the frame. mLastFrame = mCurrentFrame; mLastData = mCurrentData; mLastSample = mCurrentSample; GetNextBit( mCurrentData, mCurrentFrame, mCurrentSample ); } return; } mLastFrame = mCurrentFrame; mLastData = mCurrentData; mLastSample = mCurrentSample; } }
void I2sAnalyzer::GetFrame() { //on entering this function: //mCurrentFrame and mCurrentData are the values of the first bit -- that belongs to us -- in the frame. //mLastFrame and mLastData are the values from the bit just before. mDataBits.clear(); mDataValidEdges.clear(); mDataBits.push_back( mCurrentData ); mDataValidEdges.push_back( mCurrentSample ); mLastFrame = mCurrentFrame; mLastData = mCurrentData; mLastSample = mCurrentSample; for( ; ; ) { GetNextBit( mCurrentData, mCurrentFrame, mCurrentSample ); if( mCurrentFrame == BIT_HIGH && mLastFrame == BIT_LOW ) { if( mSettings->mBitAlignment == BITS_SHIFTED_RIGHT_1 ) { //this bit belongs to us: mDataBits.push_back( mCurrentData ); mDataValidEdges.push_back( mCurrentSample ); //we need to advance to the next bit past the frame. mLastFrame = mCurrentFrame; mLastData = mCurrentData; mLastSample = mCurrentSample; GetNextBit( mCurrentData, mCurrentFrame, mCurrentSample ); } return; } mDataBits.push_back( mCurrentData ); mDataValidEdges.push_back( mCurrentSample ); mLastFrame = mCurrentFrame; mLastData = mCurrentData; mLastSample = mCurrentSample; } }
// ------------------------------------------------------------------------------ void RFFEAnalyzer::FindParity(bool expParity, U64 extra_data) { BitState bitstate; bool data_parity; U64 parity_value; U8 flags = 0; // Get the Parity Bit on the next sample clock bitstate = GetNextBit(0); // Store away tailing sample position as the end of the Parity bit mSampleClkOffsets[1] = mSamplePosition; if (bitstate == BIT_HIGH) { parity_value = 1; data_parity = true; mSampleMarker[0] = AnalyzerResults::One; } else { parity_value = 0; data_parity = false; mSampleMarker[0] = AnalyzerResults::Zero; } if (data_parity != expParity) { flags |= (DISPLAY_AS_ERROR_FLAG | DISPLAY_AS_WARNING_FLAG | RFFE_PARITY_ERROR_FLAG); mSampleMarker[0] = AnalyzerResults::ErrorDot; } FillInFrame(RFFEAnalyzerResults::RffeParityField, parity_value, extra_data, 0, 1, flags); }
// -------------------------------------- U64 RFFEAnalyzer::GetBitStream(U8 len) { U64 data; U32 i; BitState state; DataBuilder data_builder; data_builder.Reset(&data, AnalyzerEnums::MsbFirst, len); // starting at rising edge of clk for (i = 0; i < len; i++) { state = GetNextBit(i); data_builder.AddBit(state); if (state == BIT_HIGH) { mSampleMarker[i] = AnalyzerResults::One; } else { mSampleMarker[i] = AnalyzerResults::Zero; } } mSampleClkOffsets[i] = mSamplePosition; return data; }
int YsPngUncompressor::DecodeDynamicHuffmanCode (unsigned int &hLit,unsigned int &hDist,unsigned int &hCLen, unsigned int *&hLengthLiteral,unsigned int *&hCodeLiteral, unsigned int *&hLengthDist,unsigned int *&hCodeDist, unsigned int hLengthBuf[322],unsigned int hCodeBuf[322], const unsigned char dat[],unsigned int &bytePtr,unsigned int &bitPtr) { unsigned int i; hLit=0; hDist=0; hCLen=0; hLit=GetNextMultiBit(dat,bytePtr,bitPtr,5); hDist=GetNextMultiBit(dat,bytePtr,bitPtr,5); hCLen=GetNextMultiBit(dat,bytePtr,bitPtr,4); if(YsGenericPngDecoder::verboseMode==YSTRUE) { printf("hLit=%d hDist=%d hCLen=%d\n",hLit,hDist,hCLen); } const unsigned int codeLengthLen=19; unsigned codeLengthOrder[codeLengthLen]= { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; unsigned codeLengthCode[codeLengthLen]; for(i=0; i<codeLengthLen; i++) { codeLengthCode[i]=0; } for(i=0; i<hCLen+4; i++) { codeLengthCode[codeLengthOrder[i]]=GetNextMultiBit(dat,bytePtr,bitPtr,3); // printf("Code length code[%d]=%d (for %d)\n", // codeLengthOrder[i],codeLengthCode[i],codeLengthOrder[i]); } unsigned hLengthCode[codeLengthLen],hCodeCode[codeLengthLen]; MakeDynamicHuffmanCode(hLengthCode,hCodeCode,codeLengthLen,codeLengthCode); if(YSTRUE==YsGenericPngDecoder::verboseMode) { for(i=0; i<hCLen+4; i++) { printf("CodeLengthLen[%3d]=%d HuffmanCode=%08x\n",i,codeLengthCode[i],hCodeCode[i]); } } // for(i=0; i<codeLengthLen; i++) // { // printf("[%d] %08x %08xx\n",i,hLengthCode[i],hCodeCode[i]); // } hLengthLiteral=hLengthBuf; hCodeLiteral=hCodeBuf; hLengthDist=hLengthBuf+hLit+257; hCodeDist=hCodeBuf+hLit+257; YsPngHuffmanTree *lengthTree,*lengthTreePtr; lengthTree=MakeHuffmanTree(codeLengthLen,hLengthCode,hCodeCode); unsigned int nExtr; nExtr=0; lengthTreePtr=lengthTree; while(nExtr<hLit+257+hDist+1) { if(GetNextBit(dat,bytePtr,bitPtr)) { lengthTreePtr=lengthTreePtr->one; } else { lengthTreePtr=lengthTreePtr->zero; } if(lengthTreePtr->zero==NULL && lengthTreePtr->one==NULL) { unsigned value,copyLength; value=lengthTreePtr->dat; // printf("Value=%d\n",value); if(value<=15) { hLengthBuf[nExtr++]=value; } else if(value==16) { copyLength=3+GetNextMultiBit(dat,bytePtr,bitPtr,2); // printf("copyLength=%d\n",copyLength); while(copyLength>0) { hLengthBuf[nExtr]=hLengthBuf[nExtr-1]; nExtr++; copyLength--; } } else if(value==17) { copyLength=3+GetNextMultiBit(dat,bytePtr,bitPtr,3); // printf("copyLength=%d\n",copyLength); while(copyLength>0) { hLengthBuf[nExtr++]=0; copyLength--; } } else if(value==18) { copyLength=11+GetNextMultiBit(dat,bytePtr,bitPtr,7); // printf("copyLength=%d\n",copyLength); while(copyLength>0) { hLengthBuf[nExtr++]=0; copyLength--; } } lengthTreePtr=lengthTree; // printf("nExtr=%d/%d\n",nExtr,hLit+257+hDist+1); } } if(YSTRUE==YsGenericPngDecoder::verboseMode) { for(i=0; i<hLit+257; i++) { printf("LiteralLength[%3d]=%d\n",i,hLengthLiteral[i]); } for(i=0; i<hDist+1; i++) { printf("Dist [%d] Length %d\n",i,hLengthDist[i]); } } if(YsGenericPngDecoder::verboseMode==YSTRUE) { printf("Making Huffman Code from Code Lengths\n"); } MakeDynamicHuffmanCode(hLengthLiteral,hCodeLiteral,hLit+257,hLengthLiteral); MakeDynamicHuffmanCode(hLengthDist,hCodeDist,hDist+1,hLengthDist); DeleteHuffmanTree(lengthTree); return YSOK; }
int MFString::Parse(const char *pFormat, ...) { if(!pData || !pFormat) return 0; va_list arglist; va_start(arglist, pFormat); const char *pS = pData->pMemory; int numArgs = 0; MFString format = GetNextBit(pFormat); int numChars = Match(pS, format.CStr()); while(*pFormat && numChars >= 0) { pS += numChars; ++pFormat; int length = -1; // gather format options... while(*pFormat) { int c = MFToLower(*pFormat++); if(c == 's') { MFString *pStr = va_arg(arglist, MFString*); ++numArgs; format = GetNextBit(pFormat); if(length >= 0) { MFString s(pS, (size_t)length); *pStr = s; numChars = Match(pS, format.CStr()); } else if(format.NumBytes() == 0) { *pStr = pS; } else { const char *pEnd = pS; while(*pEnd && (numChars = Match(pEnd, format.CStr())) < 0) ++pEnd; MFString s(pS, (size_t)(pEnd - pS)); *pStr = s; } pS += pStr->NumBytes(); break; } else if(c == 'd' || c == 'i') { int *pInt = va_arg(arglist, int*); ++numArgs; bool bNeg = *pS == '-'; if(*pS == '-' || *pS == '+') ++pS; *pInt = 0; while(MFIsNumeric(*pS) && ((uint32&)length)-- > 0) *pInt = *pInt*10 + *pS++ - '0'; if(bNeg) *pInt = -*pInt; format = GetNextBit(pFormat); numChars = Match(pS, format.CStr()); break; }