Windows 使用NAudio获取输入设备支持的格式
我想将NAudio用于一个录制程序,但我遇到了一个意想不到的限制。NAudio.Wave.WaveIn.GetCapabilities(deviceNumber)返回WaveCapabilities结构,但该结构中只有少数字段是公共的 我尤其需要知道设备支持哪些格式。这些资料载于: 私有支持的波形格式支持的格式Windows 使用NAudio获取输入设备支持的格式,windows,audio,naudio,Windows,Audio,Naudio,我想将NAudio用于一个录制程序,但我遇到了一个意想不到的限制。NAudio.Wave.WaveIn.GetCapabilities(deviceNumber)返回WaveCapabilities结构,但该结构中只有少数字段是公共的 我尤其需要知道设备支持哪些格式。这些资料载于: 私有支持的波形格式支持的格式 我可以将其更改为public并构建NAaudio.dll,但我想知道是否有某些原因导致该字段被标记为private?或者,还有其他地方可以找到这些信息吗?网络上有一个例子,我编辑了它,这
我可以将其更改为public并构建NAaudio.dll,但我想知道是否有某些原因导致该字段被标记为private?或者,还有其他地方可以找到这些信息吗?网络上有一个例子,我编辑了它,这对我来说很有用,可以从不同的设备上获取所有功能(这很难看,但它可以…):
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用System.Runtime.InteropServices;
使用系统集合;
名称空间4ch\u流
{
类别clsRecDevices
{
[StructLayout(LayoutKind.Sequential,Pack=4)]
公共结构WaveInCaps
{
公共短wMid;
公共短wPid;
公开版本;
[Marshallas(UnmanagedType.ByValArray,SizeConst=32)]
公共字符[]szPname;
公共uint格式;
公共短频道;
公共短期服务1;
}
[DllImport(“winmm.dll”)]
public static extern int waveInGetNumDevs();
[DllImport(“winmm.dll”,EntryPoint=“waveInGetDevCaps”)]
waveInGetDevCapsA内部公共静态外部(内部uDeviceID,
ref WaveInCaps lpCaps,int uSize);
public ArrayList arrLst=new ArrayList();
//用于存储所有录音设备字符串
静态int devcount=waveInGetNumDevs();
公共静态空头[]中间=新空头[devcount];
public static short[]Pid=新的short[devcount];
public static int[]DriverVersion=new int[devcount];
公共静态uint[]格式=新uint[devcount];
公共静态短[]通道=新短[devcount];
公共静态空头[]保留1=新空头[devcount];
公共整数计数
//返回找到的录音设备总数
{
获取{return arrLst.Count;}
}
公共字符串this[int indexer]
//返回spesipic录音设备名称
{
获取{return(string)arrLst[indexer];}
}
public clsRecDevices()//填充录音设备阵列
{
int WaveIndeviceCount=waveInGetNumDevs();//获取总计
如果(WaveIndeviceCount>0)
{
对于(int-uDeviceID=0;uDeviceID
希望能有帮助。谢谢,我相信这很管用。我最终只是把格式公之于众并进行了重建。
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
}
}
}
}
}