if(1==mpegInfo->layer) mpegInfo->samples=384;
if(mpegInfo->level==1) { if(1==mpegInfo->layer) mpegInfo->samples=384; else mpegInfo->samples=1152; *offset=start-1; }
uint8_t	getMpegFrameInfo(uint8_t *stream,uint32_t maxSearch, MpegAudioInfo *mpegInfo,MpegAudioInfo *templ,uint32_t *offset){uint32_t start=0,found=0;uint8_t  a[4];uint32_t nfq,fqindex,brindex,index;			memcpy(a+1,stream,3);			do			{								memmove(a,a+1,3);				a[3]=stream[start+3];				if(start>=maxSearch-3) break;				start++;				if(a[0]==0xff && ((a[1]&0xF0)==0xF0))				{					// Layer					mpegInfo->layer=4-(a[1]>>1)&3;						mpegInfo->level=4-(a[1]>>3)&3;					if(mpegInfo->level==3) continue;					if(mpegInfo->level==4) mpegInfo->level=3;					mpegInfo->protect=a[1]&1;					mpegInfo->padding=(a[2]>>1)&1;					mpegInfo->mode=(a[3])>>6;															fqindex=(a[2]>>2)&3;					brindex=(a[2]>>4);										// Remove impossible case					if(mpegInfo->layer==0) continue;					// Check fq					switch(mpegInfo->level)					{						case 1: mpegInfo->samplerate=MP3Fq[fqindex];break;						case 2: mpegInfo->samplerate=MP2Fq[fqindex];break;						case 3: mpegInfo->samplerate=MP2Fq[fqindex]>>1;break;						default: mpegInfo->samplerate=0;break;					}					// impossible fq					if(!mpegInfo->samplerate) continue;					// Bitrate now										// Compute bitrate					switch(mpegInfo->level)					{						case 2:						case 3:							index=4+mpegInfo->layer;							break;						case 1:							index=mpegInfo->layer;								break;						default:							continue;					}										mpegInfo->bitrate=Bitrate[index][brindex];					if(!mpegInfo->bitrate) continue;										// Check consistency					if(templ)					{						if(templ->samplerate!=mpegInfo->samplerate) continue;										}					found=1;				}							}while(!found && start<maxSearch-4);			if(!found)				{						return 0;				}/*	*/			// Sample in the packet			if(1==mpegInfo->layer) 				mpegInfo->samples=384;			else				mpegInfo->samples=1152;			*offset=start-1;						// Packet size			//L1:FrameLengthInBytes = (12 * BitRate / SampleRate + Padding) * 4					switch(mpegInfo->layer)			{				case 1:					mpegInfo->size=((12*1000*mpegInfo->bitrate)/mpegInfo->samplerate)								+mpegInfo->padding;					mpegInfo->size=mpegInfo->size+4+2*mpegInfo->protect;					break;				default:				//FrameLengthInBytes = 144 * BitRate / SampleRate + Padding					mpegInfo->size=(144*mpegInfo->bitrate*1000)/mpegInfo->samplerate;					mpegInfo->size+=mpegInfo->padding;						}			if(*offset)				{					printf("MP3: Skipped %lu bytes\n",*offset);				}#if 0						printf("Packet found : at :%d level:%d layer:%d fq:%d bitrate:%d mode:%d\n",					start-1,mpegInfo->level,mpegInfo->layer,mpegInfo->samplerate,					mpegInfo->bitrate,mpegInfo->mode);			printf("Padd:%lu, crc on:%lu size:%lu\n",mpegInfo->padding,mpegInfo->protect,								mpegInfo->size);#endif								return 1;				}