问题
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