2013-08-17 39 views
0

我想使用NAudio作爲記錄程序,但我遇到了意想不到的限制。 NAudio.Wave.WaveIn.GetCapabilities(deviceNumber)返回一個WaveInCapabilities結構,但只有該結構的幾個字段是公共的。使用NAudio獲取輸入設備支持的格式

特別是我需要知道設備支持哪些格式。該信息位於:

private SupportedWaveFormat supportedFormats;

我可以將其更改爲公開並生成NAaudio.dll,但我想知道是否有某些原因將該字段標記爲私有?還是有另一個地方,我可以找到這些信息?

回答

1

有在網絡上一個例子,我編輯它,這對我的作品讓所有不同的設備支持購買(這是相當醜陋,但它的工作原理...):

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 
       } 
      } 
     } 
    } 
} 

希望它有幫助。

+0

謝謝,我敢肯定,工作。我最終只是公開了格式並重建。 – TomJeffries