/*******************************************************************************************************
文件功能:wav文件中提取pcm数据
说明: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);/*文件数据段长度等于文件总长度-文件头长度位置*/
-
- fseek(in,44,SEEK_SET);
- fread(buf,1,length-44,in);
- fwrite(buf,1,length-44,outfile);/*文件数据段长度为a-44,但指针是指向前一个指针*/
- free( buf );
- fclose(infile);
- fclose(outfile);
- }