WAV初始化:
u8 WAV_Init(u8* wav_buf)
{
if(Check_Ifo(wav_buf,"RIFF"))
return 1;
wav1.wavlen=Get_num(wav_buf+4,4);
printf("\n\rwav1.wavlen = %ld\n\r",wav1.wavlen);
//if(Check_Ifo(wav_buf+8,"WAVE"))return 2;//WAVE错误标志
//if(Check_Ifo(wav_buf+12,"fmt "))return 3;//fmt错误标志
wav1.formart=Get_num(wav_buf+20,2);//格式类别
printf("\n\rwav1.formart = %d\n\r",wav1.formart);
wav1.CHnum=Get_num(wav_buf+22,2);//通道数
printf("\n\rwav1.CHnum = %d\n\r",wav1.CHnum);
CHanalnum=wav1.CHnum;
wav1.SampleRate=Get_num(wav_buf+24,4);//采样率
printf("\n\rwav1.SampleRate = %ld\n\r",wav1.SampleRate);
wav1.speed=Get_num(wav_buf+28,4);//音频转换数率
printf("\n\rwav1.speed = %ld\n\r",wav1.speed);
wav1.ajust=Get_num(wav_buf+32,2);//数据块调速数
printf("\n\rwav1.ajust = %d\n\r",wav1.ajust);
wav1.SampleBits=Get_num(wav_buf+34,2);//样本数据位数
printf("\n\rwav1.SampleBits = %d\n\r",wav1.SampleBits);
Bitnum=wav1.SampleBits;
//if(Check_Ifo(wav_buf+36,"data"))return 4;//数据标志错误
wav1.DATAlen=Get_num(wav_buf+40,4);//数据长度
printf("\n\rwav1.DATAlen = %d\n\r",wav1.DATAlen);
if(wav1.wavlen<0x100000)
{
printf("\n\rwav1.wavlen = %dkb\n\r",(wav1.wavlen)>>10);
}
else
{
printf("\n\rwav1.wavlen = %dMb\n\r",(wav1.wavlen)>>20);
}
if(wav1.formart==1)
printf("\n\rWAV PCM\n\r");
if(wav1.CHnum==1)
printf("\n\rsingle\n\r");
else
printf("\n\rstereo\n\r");
printf("\n\rwav1.SampleRate = %dkHz\n\r",(wav1.SampleRate)/1000);
printf("\n\rwav1.speed = %dbps\n\r",(wav1.speed)/1000);
printf("\n\rwav1.SampleBits = %dbit\n\r",wav1.SampleBits);
return 0;
}
u8 Check_Ifo(u8* pbuf1,u8* pbuf2)
{
u8 i;
for(i=0;i<4;i++)
if(pbuf1!=pbuf2)
return 1;
return 0;
}
u32 Get_num(u8* pbuf,u8 len)
{
u32 num;
if(len==2)num=(pbuf[1]<<8)|pbuf[0];
else if(len==4)num=(pbuf[3]<<24)|(pbuf[2]<<16)|(pbuf[1]<<8)|pbuf[0];
return num;
} |