2025年6月8日 星期日 乙巳(蛇)年 三月十二 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 文件格式与编码

wav文件提取出pcm数据

时间:08-16来源:作者:点击数:51

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

文件功能: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);
  • }

 

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门