把音频数据写入wave文件

使用DirectX SDK中带的CWaveFile类可以进行wave文件的读写,新建一个wave文件,并将头信息和音频数据写入文件:

CWavefile *g_pWaveFile;
 WAVEFORMATEX wfxInput;
 ZeroMemory(&wfxInput,sizeof(wfxInput));
 wfxInput.wFormatTag = WAVE_FORMAT_PCM;
 wfxInput.nSamplesPerSec = 48000;
 wfxInput.wBitsPerSample = 32;
 wfxInput.nChannels = 2;
 wfxInput.nBlockAlign = wfxInput.nChannels * (wfxInput.wBitsPerSample / 8);
 wfxInput.nAvgBytesPerSec = wfxInput.nBlockAlign * wfxInput.nSamplesPerSec;

 g_pWaveFile = new CWavefile;
 if (FAILED(g_pWaveFile->Open(L"C:\\Users\\Administrator\\Desktop\\test.wav", &wfxInput,WAVEFILE_WRITE)))
 {
  g_pWaveFile->Close();
 }

 UINT Wsize=0;
 if( FAILED( g_pWaveFile->Write( len, pAudioData, &Wsize ) ) )
  assert(NULL);

g_pWaveFile->Close();//不关闭文件头不会写入文件

交流QQ:1245178753

本文地址: http://blog.csdn.net/u011417605/article/details/51334003

你可能感兴趣的:(DirectX,XAudio2)