windows - 使用 NAudio 获取输入设备支持的格式

标签 windows audio naudio

我想将 NAudio 用于录制程序,但遇到了意想不到的限制。 NAudio.Wave.WaveIn.GetCapabilities(deviceNumber) 返回一个 WaveInCapabilities 结构,但该结构中只有少数字段是公开的。

特别是我需要知道设备支持哪些格式。该信息位于:

私有(private) SupportedWaveFormat 支持格式;

我可以将其更改为公共(public)并构建 NAaudio.dll,但我想知道是否有某些原因将该字段标记为私有(private)?或者还有其他地方我可以找到这些信息吗?

最佳答案

网上有一个示例,我对其进行了编辑,这对我来说可以从不同的设备获取所有功能(这很丑陋,但它可以工作......):

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;
namespace _4ch_stream
{
    class clsRecDevices
    {


        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        public struct WaveInCaps
        {
            public short wMid;
            public short wPid;
            public int vDriverVersion;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
            public char[] szPname;
            public uint dwFormats;
            public short wChannels;
            public short wReserved1;
        }

        [DllImport("winmm.dll")]
        public static extern int waveInGetNumDevs();
        [DllImport("winmm.dll", EntryPoint = "waveInGetDevCaps")]
        public static extern int waveInGetDevCapsA(int uDeviceID,
                             ref WaveInCaps lpCaps, int uSize);
        public ArrayList arrLst = new ArrayList();
        //using to store all sound recording devices strings 

        static int devcount = waveInGetNumDevs();
        public static short[] Mid = new short[devcount];
        public static short[] Pid = new short[devcount];
        public static int[] DriverVersion = new int[devcount];
        public static uint[] Formats = new uint[devcount];
        public static short[] Channels = new short[devcount];
        public static short[] Reserved1 = new short[devcount];

        public int Count
        //to return total sound recording devices found
        {
            get { return arrLst.Count; }
        }
        public string this[int indexer]
        //return spesipic sound recording device name
        {
            get { return (string)arrLst[indexer]; }
        }
        public clsRecDevices() //fill sound recording devices array
        {
            int waveInDevicesCount = waveInGetNumDevs(); //get total
            if (waveInDevicesCount > 0)
            {
                for (int uDeviceID = 0; uDeviceID < waveInDevicesCount; uDeviceID++)
                {
                    WaveInCaps waveInCaps = new WaveInCaps();
                    waveInGetDevCapsA(uDeviceID, ref waveInCaps,
                                      Marshal.SizeOf(typeof(WaveInCaps)));
                    arrLst.Add(new string(waveInCaps.szPname).Remove(
                               new string(waveInCaps.szPname).IndexOf('\0')).Trim());
                    Mid[uDeviceID] = waveInCaps.wMid;
                    Pid[uDeviceID] = waveInCaps.wPid;
                    Formats[uDeviceID] = waveInCaps.dwFormats;
                    Channels[uDeviceID] = waveInCaps.wChannels;
                    Reserved1[uDeviceID] = waveInCaps.wReserved1;
                    //clean garbage
                }
            }
        }
    }
}

希望它有所帮助。

关于windows - 使用 NAudio 获取输入设备支持的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18291627/

相关文章:

c# - 如何在 C# 中使用带有 ProtectSection 方法的 RsaProtectedConfigurationProvider 创建可导出的 RSA key

javascript - html音频在Macbook和ios上不起作用,但在imac上起作用—很奇怪

android - Android MediaPlayer同时提供3个音频

c++ - 使用soxr重采样时发生访问冲突

c# - 使用 Naudio 将系统音频传输到 Skype

c# - Naudio BadDeviceId 在 C# 中调用 waveInOpen 错误

c# - 从声卡 windows xp 捕获音频数据

windows - 将路径中包含空格和破折号的 Win10 目录挂载到 Ubuntu Docker 容器中

windows - 如何在 PowerShell 中将参数传递给类 Unix 命令(通过 MinGW)

windows - 如何从 Powershell 设置 Windows 服务权限?