CWaveFile类是微软提供的wav文件读写类。
1:wav文件读取:
CWaveFile * pWaveFile = new CWaveFile();
pWaveFile->Open( _T("F:\\wav8000.16.Mono.wav"), 0, WAVEFILE_READ);//读取wav文件;
WAVEFORMATEX wfx;
memcpy( &wfx, pWaveFile->GetFormat(), sizeof(WAVEFORMATEX)); // 获取文件格式;
int nwavsize = pWaveFile->GetSize();//是数据长度。 文件头长度 = 文件长度 - 文件数据长度;这里的文件头长度是56,可是一般说的wav文件头长度是44,调查一下;
delete pWaveFile;
2:写wav文件:
if( FAILED( hr = m_pWaveFile->Open( strFileName, &wfxCaptureWaveFormat, WAVEFILE_WRITE ) ) )
{
return;
}
// Write the data into the wav file
if( FAILED( hr = m_pWaveFile->Write( dwCaptureLength, (BYTE*)pbCaptureData, &dwDataWrote ) ) )
return DXTRACE_ERR_MSGBOX( TEXT("Write"), hr );
m_pWaveFile->close();