您的位置:首页 > 其它

wav文件提取出pcm数据

2014-10-21 14:25 274 查看
/*******************************************************************************************************

文件功能:wav文件中提取pcm数据

作者:HFL

日期:2014-1-12

说明:wav文件就是在pcm数据的基础上加了一文件头。文件头的大小为44个字节(没有附件字段的情况,如果有附加字段问46个字节)

,剔除文件头,就是纯pcm采样过来的数据。

pcm构成要素:采样率 ,声道个数,数据符号特性(一般8位都是无符号的)

********************************************************************************************************/

#include<stdio.h>

#include<stdlib.h>

void main()

{

FILE *infile, *outfile;

char *buf = NULL;

long length;

if((infile = fopen ("e:\\1.wav", "rb+"))==NULL)

{

printf("Open the 1.wav failed\n");

return ;

}

else

{

printf("Open the 1.wav success\n");

}

if((outfile = fopen ("e:\\2.pcm", "wb"))==NULL)

{

printf("Open the 2.pcm failed\n");

return ;

}

else

{

printf("Open the 2.pcm success\n");

}

/*获取文件的长度*/

fseek(infile,0,SEEK_END);

length=ftell(infile);

buf = (char*)malloc(length-43);/*文件数据段长度等于文件总长度-文件头长度位置*/

fwrite(buf,1,length-44,outfile);/*文件数据段长度为a-44,但指针是指向前一个指针*/

free( buf );

fclose(infile);

fclose(outfile);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: