根据前面对wav格式信息的了解:
给出如下函数:两颗星的变量指向从数据wav文件读取的音频数据,不包括wav头部信息,获得的数据直接可以放到wavoutWrite函数中进行播放输出(当然事先还要打开设备之类的).
用CFile读取wav文件数据,作为输入.
int read_wav_head(WAVEFORMATEX *wf, char **out_buffer, int *out_len, char *in_buffer, int in_len)
{
char *lp_pos;
int itmp;
lp_pos = in_buffer;
if(in_buffer == NULL || in_len == 0 || in_len < WAVE_HEADER_SIZE || wf==NULL)
return 1;
if(strncmp(lp_pos,"RIFF",4)!=0)
return -1;
lp_pos += 4;
itmp = *((int*)lp_pos);
if(itmp != (in_len-8))
return -1;
lp_pos += 4;
if(strncmp(lp_pos,"WAVEfmt ",8)!=0)
return -1;
lp_pos += 8;
itmp = *((int*)lp_pos);
if(itmp != 16)
return -1;
lp_pos += 4;
/**//*格式信息*/
memcpy(wf,lp_pos,16);
lp_pos += 16;
if(strncmp(lp_pos,"data",4)!=0)
return -1;
lp_pos += 4;
//真正的数据长度
*out_len = *((int*)lp_pos);
lp_pos += 4;
if(*out_len != (in_len - WAVE_HEADER_SIZE))
return 1;
*out_buffer = (char*)malloc(*out_len);
if(*out_buffer == NULL)
return -2;
memcpy(*out_buffer,lp_pos,*out_len);
return 0;
}