WAV文件创建

typedef struct WAVE
{
 short wFormatTag; //编码格式,包括WAVE_FORMAT_PCM,WAVEFORMAT_ADPCM等
 short nChannels; //声道数,单声道为1,双声道为2
 int nSamplesPerSec; //采样频率
 int nAvgBytesPerSec; //每秒的数据量
 short nBlockAlign; //块对齐
 short wBitsPerSample; //WAVE文件的采样大小
 short cbSize;
} WAVEFORMATEX, *PWAVEFORMATEX;

 

int m_WaveHeaderSize = 38;
 int m_WaveFormatSize = 18;
 int m_AudioDataSize =1024*1024*4;
 int m_WrittenBytes = 0;
 WAVEFORMATEX m_WaveFormatEx;
 m_WaveFormatEx.wFormatTag=1 ;
 m_WaveFormatEx.nSamplesPerSec=48000;
 m_WaveFormatEx.wBitsPerSample=16;
 m_WaveFormatEx.nChannels=2;
 m_WaveFormatEx.cbSize=0;
 m_WaveFormatEx.nBlockAlign=m_WaveFormatEx.nChannels*(m_WaveFormatEx.wBitsPerSample/8);
 m_WaveFormatEx.nAvgBytesPerSec=m_WaveFormatEx.nSamplesPerSec*m_WaveFormatEx.nBlockAlign;

 //
 FILE *m_file;
 string m_csFileName= "C://test.wav";
 m_file = fopen(m_csFileName.c_str(), "wb");
 //
 fwrite("RIFF", 1, 4, m_file);
 unsigned int Sec=(m_AudioDataSize + m_WaveHeaderSize);
 fwrite(&Sec, 1, sizeof(Sec), m_file);
 fwrite("WAVE", 1, 4, m_file);
 fwrite("fmt ", 1, 4, m_file);
 fwrite(&m_WaveFormatSize, 1, sizeof(m_WaveFormatSize), m_file);
 fwrite(&m_WaveFormatEx.wFormatTag, 1, sizeof(m_WaveFormatEx.wFormatTag), m_file);
 fwrite(&m_WaveFormatEx.nChannels, 1, sizeof(m_WaveFormatEx.nChannels), m_file);
 fwrite(&m_WaveFormatEx.nSamplesPerSec, 1, sizeof(m_WaveFormatEx.nSamplesPerSec), m_file);
 fwrite(&m_WaveFormatEx.nAvgBytesPerSec, 1, sizeof(m_WaveFormatEx.nAvgBytesPerSec), m_file);
 fwrite(&m_WaveFormatEx.nBlockAlign, 1, sizeof(m_WaveFormatEx.nBlockAlign), m_file);
 fwrite(&m_WaveFormatEx.wBitsPerSample, 1, sizeof(m_WaveFormatEx.wBitsPerSample), m_file);
 fwrite(&m_WaveFormatEx.cbSize, 1, sizeof(m_WaveFormatEx.cbSize), m_file);
 fwrite("data", 1, 4, m_file);
 fwrite(&m_AudioDataSize, 1, sizeof(m_AudioDataSize), m_file);

 char *Data = new char[1024*1024*4];
 fwrite(Data, 1, 1024*1024*4, m_file);
 fclose(m_file);

 delete []Data;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值