ivymike
ivymike

Reputation: 1591

How to programmatically retrieve the name of default audio input device on Windows XP?

How to programmatically retrieve the name of default audio input device on Windows XP (eg: "Realtek AC97 Audio")?

I can access it through the registry key "HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper", but I'm not sure if this is always reliable. Also, I can retrieve the names of all devices by using waveInGetDevCaps() api, but I'm not sure how to get the default audio device name using it.

Thanks

Upvotes: 2

Views: 5028

Answers (2)

Midas
Midas

Reputation: 7131

Try using WAVE_MAPPER:

#include <windows.h>
#include <stdio.h>

void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) {
    printf("Device opened for recording!\n");
}

int main(void) {
    HWAVEIN hwi;
    WAVEFORMATEX wfx;
    WAVEINCAPS wic;
    int sampleRate = 44100;

    wfx.wFormatTag = WAVE_FORMAT_PCM;
    wfx.nChannels = 2;
    wfx.nSamplesPerSec = sampleRate;
    wfx.nAvgBytesPerSec = sampleRate * 2;
    wfx.wBitsPerSample = 16;
    wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
    wfx.cbSize = 0;

    //Get capabilities using WAVE_MAPPER (ID for Microsoft default assigned device)
    waveInOpen(&hwi, WAVE_MAPPER, &wfx, (DWORD) &waveInProc, 0, CALLBACK_FUNCTION);
    waveInGetDevCaps(WAVE_MAPPER, &wic, sizeof(wic));

    //Use the received manufacturer id to get the device's real name
    waveInGetDevCaps(wic.wMid, &wic, sizeof(wic));
    printf("%s\n", wic.szPname);

    return 1;
}

Upvotes: 2

Damon
Damon

Reputation: 70126

OpenAL to the rescue! Since OpenAL lets you query that type of information, how to do it must be hidden in the source code.

Digging through it reveals this code which leads to waveInGetDevCaps.

The WAVEINCAPS structure holds, among other data, the name of the device.

Upvotes: 1

Related Questions