none
How to choose the correct device for audio recording?

    Question

  • We record video and audio of our game.

    waveInGetNumDevs() indicates that there are more than one devices. And we can't get correct audio data untill the default device is "Stereo Mix". We don't know how to choose the correct device with waveInOpen(). Now we are passing in WAVE_MAPPER. But we can't know whether a device is OK for game's audio recording.

    Here are Windows' audio dialog, it's only OK when "Stereo Mix" is selected as default, which means its device ID is 0.

    Audio Dialog

    Tuesday, March 13, 2012 5:15 AM

Answers

  • All waveIn devices can be used for sound recording.  The question is, what do you want to record?

    If you just want to record "whatever's going into the computer" you should use the default device - that is, the one with device ID 0.

    If you want to record what's going out of the computer, you should not use waveIn at all and should migrate to using WASAPI loopback capture.

    If you have more specialized needs you can enumerate all the inputs and look at their capabilities, or defer the choice to the user by popping up UI.


    Matthew van Eerde

    • Marked as answer by niexuchina Tuesday, March 20, 2012 1:35 AM
    Monday, March 19, 2012 3:45 PM
  • Stereo Mix.

    Matthew van Eerde

    • Marked as answer by niexuchina Wednesday, May 23, 2012 12:49 AM
    Tuesday, May 22, 2012 3:16 PM

All replies

  • I also notice that there isn't a "Stereo Mix" device on some machines, which means that it's not possible to do audio recording.
    Tuesday, March 13, 2012 6:22 AM
  • Stereo Mix is an optional hardware/driver feature; not all hardware and drivers support it.

    In Vista and later you can record what goes out of the speakers using WASAPI loopback recording:

    http://blogs.msdn.com/b/matthew_van_eerde/archive/2008/12/16/sample-wasapi-loopback-capture-record-what-you-hear.aspx

    Both of these suffer from the problem that you won't get just the audio output of your game, but also anything else that is playing at the time.


    Matthew van Eerde

    Tuesday, March 13, 2012 3:57 PM
  • You can tell which waveIn device is which by doing something like this, and looking at caps.szPname:

        UINT devs = waveInGetNumDevs();
        LOG(L"waveIn devices: %u", devs);
        for (UINT dev = 0; dev < devs; dev++) {
            WAVEINCAPS caps = {};
            MMRESULT mmr = waveInGetDevCaps(dev, &caps, sizeof(caps));
            
            if (MMSYSERR_NOERROR != mmr) {
                 LOG(L"waveInGetDevCaps failed: mmr = 0x%08x", mmr);
                 return mmr;
            }
            
            LOG(
                L"-- waveIn device #%u --\n"
                L"Manufacturer ID: %u\n"
                L"Product ID: %u\n"
                L"Version: %u.%u\n"
                L"Product Name: %s\n"
                L"Formats: 0x%x\n"
                L"Channels: %u\n"
                L"Reserved: %u\n"
                ,
                dev,
                caps.wMid,
                caps.wPid,
                caps.vDriverVersion / 256, caps.vDriverVersion % 256,
                caps.szPname,
                caps.dwFormats,
                caps.wChannels,
                caps.wReserved1
            );
        }
    


    Matthew van Eerde

    Tuesday, March 13, 2012 4:13 PM
  • See http://blogs.msdn.com/b/matthew_van_eerde/archive/2012/03/13/sample-how-to-enumerate-wavein-and-waveout-devices-on-your-system.aspx for a sample on waveIn enumeration and device capability checking.

    Matthew van Eerde

    Tuesday, March 13, 2012 4:59 PM
  • I can't find any document telling that something in caps.szPname indicates it can be used for sound recording or not. The only thing I can do till now is skipping CD Audio, if it's the default device.

    I still need some reliable way to find the correct recording device, precisely. Is it possible on windows?

    Monday, March 19, 2012 6:16 AM
  • All waveIn devices can be used for sound recording.  The question is, what do you want to record?

    If you just want to record "whatever's going into the computer" you should use the default device - that is, the one with device ID 0.

    If you want to record what's going out of the computer, you should not use waveIn at all and should migrate to using WASAPI loopback capture.

    If you have more specialized needs you can enumerate all the inputs and look at their capabilities, or defer the choice to the user by popping up UI.


    Matthew van Eerde

    • Marked as answer by niexuchina Tuesday, March 20, 2012 1:35 AM
    Monday, March 19, 2012 3:45 PM
  • We want to record our game's sound. The default device may be not capable for that. The only device which can do that is Stereo Mix, or something else like it. But this device may not exist, or it exists but has been disabled.

    I wonder whether waveIn* APIs can meet our goal, which is capturing all sound from the game. And if not, is there any way else can do that?

    Tuesday, March 20, 2012 8:26 AM
  • WASAPI is only available above Vista. Is there something similar on Xp?
    Tuesday, May 22, 2012 11:23 AM
  • Stereo Mix.

    Matthew van Eerde

    • Marked as answer by niexuchina Wednesday, May 23, 2012 12:49 AM
    Tuesday, May 22, 2012 3:16 PM