views:

832

answers:

2

Hello,

How would it be possible to capture the audio programmatically? I am implementing an application that streams in real time the desktop on the network. The video part is finished. I need to implement the audio part. I need a way to get PCM data from the sound card to feed to my encoder (implemented using Windows Media Format).

I think the answer is related to the openMixer(), waveInOpen() functions in Win32 API, but I am not sure exactly what should I do.

How to open the necessary channel and how to read PCM data from it?

Thanks in advance.

+2  A: 

I don't think there is a direct way to do this using the OS - it's a feature that may (or may not) be present on the sound card. Some sound cards have a loopback interface - Creative calls it "What U Hear". You simply select this as the input rather than the microphone, and record from it using the normal waveInOpen() that you already know about.

If the sound card doesn't have this feature then I think you're out of luck other than by doing something crazy like making your own driver. Or you could convince your users to run a cable from the speaker output to the line input :)

MrZebra
+1  A: 

The new Windows Vista Core Audio APIs have support for this explicitly (called Loopback Reqcording), so if you can live with a Vista only application this is the way to go.

See the Loopback Recording article on MSDN for instructions on how to do this.

Nick Haddad