我在做一个录音程序设计,但是在录音后的数据保存上有点搞不清楚,下面是我在数据上加的WAV文件头,但是保存后,文件大小总是1KB,问题出在哪里呢?
//定义WAVE文件结构
DWORD WaveHeaderSize=38;
DWORD WaveFormatSize=sizeof(WAVEFORMATEX);
DWORD AudioDataSize=sizeof(m_dwDataLength);
WAVEFORMATEX WaveFormatEx;
WaveFormatEx.wFormatTag =WAVE_FORMAT_PCM;
WaveFormatEx.nSamplesPerSec =44100;
WaveFormatEx.wBitsPerSample =16;
WaveFormatEx.nChannels =2;
WaveFormatEx.cbSize =0;
WaveFormatEx.nBlockAlign =WaveFormatEx.nChannels *WaveFormatEx.wBitsPerSample /8;
WaveFormatEx.nAvgBytesPerSec =WaveFormatEx.nSamplesPerSec *WaveFormatEx.nBlockAlign ;
//创建新文件
CFile m_file;
CFileException fileException;
CString m_csFileName=SaveDlg.GetPathName ();
m_file.Open (m_csFileName,CFile::modeCreate | CFile::modeReadWrite,&fileException);
//写入WAV文件头,按顺序写入
m_file.SeekToBegin ();
m_file.Write ("RIFF",4);
unsigned int Sec=(AudioDataSize+WaveHeaderSize);
m_file.Write (&Sec,sizeof(Sec));
m_file.Write ("WAVE",4);
m_file.Write ("fmt ",4);
m_file.Write (&WaveFormatSize,sizeof(WaveFormatSize));
m_file.Write (&WaveFormatEx.wFormatTag ,sizeof(WaveFormatEx.wFormatTag ));
m_file.Write (&WaveFormatEx.nChannels ,sizeof(WaveFormatEx.nChannels ));
m_file.Write (&WaveFormatEx.nSamplesPerSec ,sizeof(WaveFormatEx.nSamplesPerSec ));
m_file.Write (&WaveFormatEx.nAvgBytesPerSec ,sizeof(WaveFormatEx.nAvgBytesPerSec ));
m_file.Write (&WaveFormatEx.nBlockAlign ,sizeof(WaveFormatEx.nBlockAlign ));
m_file.Write (&WaveFormatEx.wBitsPerSample ,sizeof(WaveFormatEx.wBitsPerSample ));
m_file.Write (&WaveFormatEx.cbSize ,sizeof(WaveFormatEx.cbSize ));
m_file.Write ("data",4);
m_file.Write (&AudioDataSize,sizeof(AudioDataSize));
//写入音频数据,把音频数据放到WAV文件头后写入
m_file.Write (m_pSaveBuffer,sizeof(AudioDataSize));