如何检查麦克风和扬声器是否来自同一个声卡?

发布于 2024-07-11 06:06:45 字数 97 浏览 7 评论 0原文

我的问题是如何在Windows平台上检查麦克风和扬声器是否来自同一个声卡。 如果它们来自不同的卡,那么处理时序的逻辑就会不同。 我同时使用 DSound 和 WMME API。

My question is how to check if a microphone and a speaker are from the same sound card on Windows platform. If they are from different cards, then the logic to handling timing will be different. I'm using both DSound and WMME API.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫性小仙女 2024-07-18 06:06:45

WMI 确实提供了一些有关声卡的信息。 我还没能弄清楚的是它是否给予足够。 使用“WMI 代码创建器< /a>”以下脚本列出了 Win32_SoundDevice 对象存储的所有内容:

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_SoundDevice",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_SoundDevice instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
    Wscript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
    Wscript.Echo "CreationClassName: " & objItem.CreationClassName
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "DMABufferSize: " & objItem.DMABufferSize
    Wscript.Echo "ErrorCleared: " & objItem.ErrorCleared
    Wscript.Echo "ErrorDescription: " & objItem.ErrorDescription
    Wscript.Echo "InstallDate: " & objItem.InstallDate
    Wscript.Echo "LastErrorCode: " & objItem.LastErrorCode
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "MPU401Address: " & objItem.MPU401Address
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
    If isNull(objItem.PowerManagementCapabilities) Then
    Wscript.Echo "PowerManagementCapabilities: "
    Else
    Wscript.Echo "PowerManagementCapabilities: " & Join(objItem.PowerManagementCapabilities, ",")
    End If
    Wscript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
    Wscript.Echo "ProductName: " & objItem.ProductName
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "StatusInfo: " & objItem.StatusInfo
    Wscript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
    Wscript.Echo "SystemName: " & objItem.SystemName
Next

在我的笔记本电脑上运行它,

-----------------------------------
Win32_SoundDevice instance
-----------------------------------
Availability: 
Caption: ATI Function Driver for High Definition Audio - ATI AA01
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_SoundDevice
Description: ATI Function Driver for High Definition Audio - ATI AA01
DeviceID: HDAUDIO\FUNC_01&VEN_1002&DEV_AA01&SUBSYS_00AA0100&REV_1000\5&BB7E0F3&0&0001
DMABufferSize: 
ErrorCleared: 
ErrorDescription: 
InstallDate: 
LastErrorCode: 
Manufacturer: ATI
MPU401Address: 
Name: ATI Function Driver for High Definition Audio - ATI AA01
PNPDeviceID: HDAUDIO\FUNC_01&VEN_1002&DEV_AA01&SUBSYS_00AA0100&REV_1000\5&BB7E0F3&0&0001
PowerManagementCapabilities: 
PowerManagementSupported: False
ProductName: ATI Function Driver for High Definition Audio - ATI AA01
Status: OK
StatusInfo: 3
SystemCreationClassName: Win32_ComputerSystem
SystemName: BABEL
-----------------------------------
Win32_SoundDevice instance
-----------------------------------
Availability: 
Caption: Conexant High Definition SmartAudio 221
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_SoundDevice
Description: Conexant High Definition SmartAudio 221
DeviceID: HDAUDIO\FUNC_01&VEN_14F1&DEV_5051&SUBSYS_1179FF5B&REV_1000\4&2DBDAC14&0&0001
DMABufferSize: 
ErrorCleared: 
ErrorDescription: 
InstallDate: 
LastErrorCode: 
Manufacturer: Conexant
MPU401Address: 
Name: Conexant High Definition SmartAudio 221
PNPDeviceID: HDAUDIO\FUNC_01&VEN_14F1&DEV_5051&SUBSYS_1179FF5B&REV_1000\4&2DBDAC14&0&0001
PowerManagementCapabilities: 
PowerManagementSupported: False
ProductName: Conexant High Definition SmartAudio 221
Status: OK
StatusInfo: 3
SystemCreationClassName: Win32_ComputerSystem
SystemName: BABEL

我不知道其中是否有任何帮助。 这是一个很难回答的问题。

WMI does give some information about sound cards. What I haven't been able to find out yet is whether its giving enough. Using "WMI Code Creator" the following script lists everything that the Win32_SoundDevice object stores:

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_SoundDevice",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_SoundDevice instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
    Wscript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
    Wscript.Echo "CreationClassName: " & objItem.CreationClassName
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DeviceID: " & objItem.DeviceID
    Wscript.Echo "DMABufferSize: " & objItem.DMABufferSize
    Wscript.Echo "ErrorCleared: " & objItem.ErrorCleared
    Wscript.Echo "ErrorDescription: " & objItem.ErrorDescription
    Wscript.Echo "InstallDate: " & objItem.InstallDate
    Wscript.Echo "LastErrorCode: " & objItem.LastErrorCode
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "MPU401Address: " & objItem.MPU401Address
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
    If isNull(objItem.PowerManagementCapabilities) Then
    Wscript.Echo "PowerManagementCapabilities: "
    Else
    Wscript.Echo "PowerManagementCapabilities: " & Join(objItem.PowerManagementCapabilities, ",")
    End If
    Wscript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
    Wscript.Echo "ProductName: " & objItem.ProductName
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "StatusInfo: " & objItem.StatusInfo
    Wscript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
    Wscript.Echo "SystemName: " & objItem.SystemName
Next

Running that on my laptop gives

-----------------------------------
Win32_SoundDevice instance
-----------------------------------
Availability: 
Caption: ATI Function Driver for High Definition Audio - ATI AA01
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_SoundDevice
Description: ATI Function Driver for High Definition Audio - ATI AA01
DeviceID: HDAUDIO\FUNC_01&VEN_1002&DEV_AA01&SUBSYS_00AA0100&REV_1000\5&BB7E0F3&0&0001
DMABufferSize: 
ErrorCleared: 
ErrorDescription: 
InstallDate: 
LastErrorCode: 
Manufacturer: ATI
MPU401Address: 
Name: ATI Function Driver for High Definition Audio - ATI AA01
PNPDeviceID: HDAUDIO\FUNC_01&VEN_1002&DEV_AA01&SUBSYS_00AA0100&REV_1000\5&BB7E0F3&0&0001
PowerManagementCapabilities: 
PowerManagementSupported: False
ProductName: ATI Function Driver for High Definition Audio - ATI AA01
Status: OK
StatusInfo: 3
SystemCreationClassName: Win32_ComputerSystem
SystemName: BABEL
-----------------------------------
Win32_SoundDevice instance
-----------------------------------
Availability: 
Caption: Conexant High Definition SmartAudio 221
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_SoundDevice
Description: Conexant High Definition SmartAudio 221
DeviceID: HDAUDIO\FUNC_01&VEN_14F1&DEV_5051&SUBSYS_1179FF5B&REV_1000\4&2DBDAC14&0&0001
DMABufferSize: 
ErrorCleared: 
ErrorDescription: 
InstallDate: 
LastErrorCode: 
Manufacturer: Conexant
MPU401Address: 
Name: Conexant High Definition SmartAudio 221
PNPDeviceID: HDAUDIO\FUNC_01&VEN_14F1&DEV_5051&SUBSYS_1179FF5B&REV_1000\4&2DBDAC14&0&0001
PowerManagementCapabilities: 
PowerManagementSupported: False
ProductName: Conexant High Definition SmartAudio 221
Status: OK
StatusInfo: 3
SystemCreationClassName: Win32_ComputerSystem
SystemName: BABEL

I don't know if there's anything in there that helps. It's a tough question.

温柔戏命师 2024-07-18 06:06:45

假设您有输入和输出设备的 ID,您可以使用类似以下内容来获取相应的混音器 ID。 如果两者相同,则两者都连接到同一个混音器,并且很可能是同一物理硬件的一部分。

    /// <summary>
    /// Get the ID of the mixer associated with the given input device ID
    /// Returns -1 if no such mixer can be found
    /// </summary>
    static public int GetMixerIdInput(int inputId)
    {
        int mixerId = -1;
        int result = MmeMixerApi.mixerGetID(inputId, ref mixerId, MIXER_OBJECTFLAG.WAVEIN);
        if (((MMError)result != MMError.MMSYSERR_NOERROR) &&
            ((MMError)result != MMError.MMSYSERR_NODRIVER))
        {
            throw new MmeException((MMError)result);
        }
        return mixerId;
    }

    /// <summary>
    /// Get the ID of the mixer associated with the given output device ID
    /// Returns -1 if no such mixer can be found
    /// </summary>
    static public int GetMixerIdOutput(int outputId)
    {
        int mixerId = -1;
        int result = MmeMixerApi.mixerGetID(outputId, ref mixerId, MIXER_OBJECTFLAG.WAVEOUT);
        if (((MMError)result != MMError.MMSYSERR_NOERROR) &&
            ((MMError)result != MMError.MMSYSERR_NODRIVER))
        {
            throw new MmeException((MMError)result);
        }
        return mixerId;
    }

如果您只有输入设备的名称,则可以使用类似以下内容来查找设备 ID:

    /// <summary>
    /// Find the ID of the input device given a name
    /// </summary>
    static public int GetWaveInputId(string name)
    {
        int id = MmeWaveApi.WAVE_MAPPER;
        int devCount = MmeWaveApi.waveInGetNumDevs();
        WAVEINCAPS caps = new WAVEINCAPS();
        for (int dev = 0; (dev < devCount) && (id == MmeWaveApi.WAVE_MAPPER); dev++)
        {
            int result = MmeWaveApi.waveInGetDevCaps(dev, ref caps, Marshal.SizeOf(caps));
            if ((MMError)result == MMError.MMSYSERR_NOERROR)
            {
                if (string.Compare(name, 0, caps.szPname, 0, Math.Min(name.Length, caps.szPname.Length)) == 0)
                {
                    id = dev;
                }
            }
        }
        return id;
    }

Assuming you have the ID of the input and output devices, you could use something like the following to get the corresponding mixer IDs. If both are the same, both are attached to the same mixer, and most likely part of the same physical hardware.

    /// <summary>
    /// Get the ID of the mixer associated with the given input device ID
    /// Returns -1 if no such mixer can be found
    /// </summary>
    static public int GetMixerIdInput(int inputId)
    {
        int mixerId = -1;
        int result = MmeMixerApi.mixerGetID(inputId, ref mixerId, MIXER_OBJECTFLAG.WAVEIN);
        if (((MMError)result != MMError.MMSYSERR_NOERROR) &&
            ((MMError)result != MMError.MMSYSERR_NODRIVER))
        {
            throw new MmeException((MMError)result);
        }
        return mixerId;
    }

    /// <summary>
    /// Get the ID of the mixer associated with the given output device ID
    /// Returns -1 if no such mixer can be found
    /// </summary>
    static public int GetMixerIdOutput(int outputId)
    {
        int mixerId = -1;
        int result = MmeMixerApi.mixerGetID(outputId, ref mixerId, MIXER_OBJECTFLAG.WAVEOUT);
        if (((MMError)result != MMError.MMSYSERR_NOERROR) &&
            ((MMError)result != MMError.MMSYSERR_NODRIVER))
        {
            throw new MmeException((MMError)result);
        }
        return mixerId;
    }

If you only have the name for the input device, you can use something like the following to find the device ID:

    /// <summary>
    /// Find the ID of the input device given a name
    /// </summary>
    static public int GetWaveInputId(string name)
    {
        int id = MmeWaveApi.WAVE_MAPPER;
        int devCount = MmeWaveApi.waveInGetNumDevs();
        WAVEINCAPS caps = new WAVEINCAPS();
        for (int dev = 0; (dev < devCount) && (id == MmeWaveApi.WAVE_MAPPER); dev++)
        {
            int result = MmeWaveApi.waveInGetDevCaps(dev, ref caps, Marshal.SizeOf(caps));
            if ((MMError)result == MMError.MMSYSERR_NOERROR)
            {
                if (string.Compare(name, 0, caps.szPname, 0, Math.Min(name.Length, caps.szPname.Length)) == 0)
                {
                    id = dev;
                }
            }
        }
        return id;
    }
后eg是否自 2024-07-18 06:06:45

切勿使用 WMI(此处无需执行任何操作)
使用MM api。

Never use WMI (nothing to do here)
Use MM apis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文