how to save audio data in memory as a wav file?

2019-08-19 07:53发布

When an application calls waveOutWrite(HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh) on windows, I save a copy of the audio data (pointed to by pwh->lpData) sent to the Audio Card in memory.

Now I want to save the audio data as a WAV format file on the disk, how should I do this?

I have the pointer to the audio data block and the size of the audo data.

标签: c winapi save wav
2条回答
狗以群分
2楼-- · 2019-08-19 08:00

The wav format is pretty trivial, and easy to write your own implementation for. Alternatively, you could use a library like libsndfile.

查看更多
相关推荐>>
3楼-- · 2019-08-19 08:00

With legacy multimedia API you will use mmioOpen, mmioCreateChunk, mmioWrite family of functions. Here is a code snippet: WAV saving?. The API allows you to write these RIFF files, however the structure is not so much complex and you can write into the binary file directly.

Still WinAPI, though not so well matching your waveOutWrite:

  • With DirectShow API you need WavDest Sample and a filter graph that uses it to write incoming data into file.
  • With most recent Media Foundation API WavSink Sample is going to be helpful.
查看更多
登录 后发表回答