How do I capture the audio that is being played?
Asked Answered
C

4

30

Does anyone know how to programmatically capture the sound that is being played (that is, everything that is coming from the sound card, not the input devices such as a microphone).

Calaboose answered 17/10, 2008 at 8:55 Comment(0)
K
24

Assuming that you are talking about Windows, there are essentially three ways to do this.

The first is to open the audio device's main output as a recording source. This is only possible when the driver supports it, although most do these days. Common names for the virtual device are "What You Hear" or "Wave Out". You will need to use a suitable API (see WaveIn or DirectSound in MSDN) to do the capturing.

The second way is to write a filter driver that can intercept the audio stream before it reaches the physical device. Again, this technique will only work for devices that have a suitable driver topology and it's certainly not for the faint-hearted.

This means that neither of these options will be guaranteed to work on a PC with arbitrary hardware.

The last alternative is to use a virtual audio device, such as Virtual Audio Cable. If this device is set as the defualt playback device in Windows then all well-behaved apps will play through it. You can then record from the same device to capture the summed output. As long as you have control over the device that the application you want to record uses then this option will always work.

All of these techniques have their pros and cons - it's up to you to decide which would be the most suitable for your needs.

Kymberlykymograph answered 17/10, 2008 at 13:45 Comment(2)
Are any of these methods guaranteed to work on any Vista/later PC, seeing as it comes with a redesign of the audio subsystem? Or are we still in this "might work on some but not others" situation?Ancel
Can you please give example code of WaveIn method. I used waveInGetDevCaps but it only gives me microphone. Is it possible to record using the waveInXXX functions a device from waveOutGetDevCaps?Platina
S
3

You can use the Waveform Audio Interface, there is an MSDN article on how to access it per PInvoke.

In order to capture the sound that is being played, you just need to open the playback device instead of the microphone. Open for input, of course, not for output ;-)

Sulphurbottom answered 17/10, 2008 at 9:57 Comment(0)
C
0

If you were using OSX, Audio Hijack Pro from Rogue Amoeba probably is the easiest way to go.

Anyway, why not just looping your audio back into your line in and recording that? This is a very simple solution. Just plug a cable in your audio output jack and your line in jack and start recordung.

Caffrey answered 4/11, 2008 at 20:7 Comment(1)
It is simple, but it is very sucky for obvious reasons (in case it's not obvious: this takes a digital signal, transforms it to analogue and then back, instead of just recording it directly in digital).Ancel
S
0

You have to enable device stero mix. if you do this, direct sound find this device.

Sabelle answered 23/2, 2009 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.