views:

116

answers:

4

How can I decode a wav file (RIFF) containing PCM data on Windows into raw samples (so that I can feed it to ASIO) on win32?

I don't have time to reinvent the wheel. If there's a library out there that does the whole "play a wav file into ASIO" thing at once, that would be nice. ASIO is simple enough, though, and has many examples for Windows online. If only I had the wav file as raw PCM data to feed to it!

I've tried to use libsndfile, but there aren't any examples of how to use it on Windows out there, and it will not compile on Windows. (They cross-compile it and release a binary currently.)

There HAS to be a way to do this using the MS API... what is it?

It would be nice if it converted it to 16 bit 44.1 kHz audio so that I can feed it to ASIO, but I can deal with hooking the two bits together, if only someone can give me a hint as to how to decode a wav file into raw samples on Windows,

+2  A: 

The .wav header-file is dead simple (a tutorial), and the PCM encoded data can probably be fed directly to ASIO once you locate them (by parsing a few simple fields of the header)

S.C. Madsen
Can you find or provide an example of decoding an existing PCM WAV file?
Thomas
Thank you for the example of decoding an existing PCM WAV file. Do you know of a way to use the Windows API to decode the header rather than parsing it out by hand?
Thomas
Sadly no, but as indicated you will quickly have the code to parse "by hand" up and running, Good luck
S.C. Madsen
[This](http://www.gidforums.com/t-10185.html) article points out problems in the code you link to, and offers solutions.
Thomas
Right, I think ive mainly used the net for "guides" on the .wav header format, but always written the actual parse-code myself...
S.C. Madsen
+2  A: 

See this.

This is encapsulated in the WAVEFORMATEX structure on Win32.

bobobobo
Also see [this](http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html) file format explanation.
Thomas
More info on format codes [here](http://www.signalogic.com/index.pl?page=ms_waveform)
Thomas
The opposite example (creating a WAV file from scratch) is included here: http://blogs.msdn.com/b/ericlippert/archive/2005/04/15/desafinado-part-four-rolling-your-own-wav-files.aspx
Thomas
A: 

They aren't parts of the Windows API, but since I don't have much experience working directly with it I'll just tell you about a couple tools I know of/have used that will do what you want.

Python has the aifc module. FFmpeg is another option if you don't want to use Python and are fine with calling external programs from your code.

EDIT: as you seem to be doing this for work, you'll probably want to take a look at http://ffmpeg.org/legal.html if you think about using FFmpeg (which you probably won't since other people have been giving WinAPI-related info), since FFmpeg uses either a version of the LGPL or the GPL depending on what options you use/how you configure it.

JAB
A: 

If you grab the source code tarball for libsndfile you will find it contains a number of example programs on the examples/ and programs/ directories.

Erik de Castro Lopo