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;