用c语言把wav文件转换成数字放到txt文件里面

#include <stdio.h>       
#include <stdlib.h>         
#include <math.h>
#include <stdafx.h>

#define  W  128   //每次读写文件的数据量  

int    FileSet=0;      //定义一个整型变量, 用于保存fseek函数的返回值
int     FileEnd=0;    //整个文件的字节数 
int     FileLength=0;  //文件的数据长度。(注:每2个字节作为一个数据 )
short InputData[W];   //文件读写数据缓冲区  

main()
{
 FILE *Ifp,*Ofp,*ttt; //定义文件读写指针 
 Ifp = fopen("1a.wav","rb");    /*以只读方式打开1a.wav文件*/
 Ofp = fopen(" ProcessedFile.wav","wb");/*以只写方式使用ProcessedFile.wav文件.(注:这个文件本身并不存在,但通过这条语句可以创建这个文件)*/
 ttt=fopen("hao.txt","w");

fseek(Ifp,0L,SEEK_END);
FileEnd=ftell(Ifp);
printf("%d/n",FileEnd);
rewind(Ifp);
FileLength=FileEnd/2;

while(FileLength>=W)
{
fread(InputData,sizeof(short),W,Ifp);
for(int i=0;i<W;i++)
{
fprintf(ttt,"%d   ",InputData[i]);
}
FileLength-=W;
}
fread(InputData,sizeof(short),FileLength,Ifp); 
for(int i=0;i<FileLength;i++)
{

fprintf(ttt,"%d   ",InputData[i]);

}
return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值