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

删除回忆录丶 提交于 2019-12-13 05:35:15

问题


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.


回答1:


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




回答2:


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.


来源:https://stackoverflow.com/questions/12438115/how-to-save-audio-data-in-memory-as-a-wav-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!