如何以编程方式检索Windows XP上的默认音频输入设备的名称?

时间:2011-04-27 11:56:45

标签: winapi visual-c++ audio windows-xp

如何以编程方式检索Windows XP上默认音频输入设备的名称(例如:“Realtek AC97 Audio”)?

我可以通过注册表项“HKEY_CURRENT_USER \ Software \ Microsoft \ Multimedia \ Sound Mapper”访问它,但我不确定这是否总是可靠的。另外,我可以使用waveInGetDevCaps()api检索所有设备的名称,但我不知道如何使用它来获取默认的音频设备名称。

由于

2 个答案:

答案 0 :(得分:2)

尝试使用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;
}

答案 1 :(得分:1)

OpenAL救援!由于OpenAL允许您查询该类型的信息,因此必须将其隐藏在源代码中。

挖掘它会显示this code,这会导致waveInGetDevCaps

除其他数据外,WAVEINCAPS结构还包含设备名称。