Sound from mic vs sound from speaker

二次信任 提交于 2019-12-08 12:02:26

问题


I want to capture audio from both the mic and the speaker - separately. How can I distinguish between them? I can capture one or the other using the Wave API, e.g., WaveInOpen().

When I enumerate the devices using waveInGetNumDevs() and waveInGetDevCaps()/waveoutGetDevCaps(), there seems to be no information related to a particular end-point device (e.g., mic or speaker). I only see the following, which are adapter devices:

HD Read Audio Input
HD Read Audio Output
Webcam ...


回答1:


I've actually no knowledge of the windows API so my answer isn't probably the best and there maybe even better ways.

    HRESULT hr = CoInitialize(NULL);
    IMMDeviceEnumerator *pEnum = NULL;
    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnum);
    if(SUCCEEDED(hr))
    {
      IMMDeviceCollection *pDevices;
      // Enumerate the output devices.
      hr = pEnum->EnumAudioEndpoints(eAll, DEVICE_STATE_ACTIVE, &pDevices);
      // You can choose between eAll, eCapture or eRender
    }

With that you'd be able to distinguish between input (capture) and output (render). (That's what you wanted right?)

The code is taken from this article. You may look at it for the correct API calls and libraries, it even might give you some more information.

Hope that's helpfull.



来源:https://stackoverflow.com/questions/8545268/sound-from-mic-vs-sound-from-speaker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!