Exemplo n.º 1
0
        public SoundFormat[] GetDeviceFormats(string deviceId)
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentNullException("deviceId");
            }
            uint uintId;

            if (!uint.TryParse(deviceId, out uintId))
            {
                throw new ArgumentException("deviceId");
            }
            uint nDevice = MMInterop.waveInGetNumDevs();

            if (uintId <= nDevice - 1)
            {
                MMInterop.WAVEINCAPS caps = new MMInterop.WAVEINCAPS();
                int mmr = MMInterop.waveInGetDevCaps(uintId, ref caps, (uint)Marshal.SizeOf(caps));
                if (mmr != 0)
                {
                    throw new SoundException("waveInGetDevCaps", mmr);
                }
                return(Util.WaveFormatToSoundFormats((MMInterop.WaveFormat)caps.dwFormats));
            }
            throw new SoundException("Device not found.");
        }
Exemplo n.º 2
0
        public SoundDevice[] GetDevices()
        {
            uint numDevices            = MMInterop.waveInGetNumDevs();
            List <SoundDevice> devices = new List <SoundDevice>((int)numDevices);

            for (uint i = 0; i < numDevices; i++)
            {
                // Get device capabilities
                MMInterop.WAVEINCAPS caps = new MMInterop.WAVEINCAPS();
                int mmr = MMInterop.waveInGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
                if (mmr == MMInterop.MMSYSERR_NODRIVER)
                {
                    // No device driver is present.
                    continue;
                }
                if (mmr != 0)
                {
                    throw new SoundException("waveInGetDevCaps", mmr);
                }
                // Compare device name to loopback device names to see if
                // it is a loopback device
                bool isLoopback = false;
                foreach (string loopbackName in loopbackDeviceNames)
                {
                    if (loopbackName.Equals(caps.szPname))
                    {
                        isLoopback = true;
                        break;
                    }
                }
                SoundDevice device = new SoundDevice(i.ToString(), caps.szPname, isLoopback);
                devices.Add(device);
            }
            return(devices.ToArray());
        }
Exemplo n.º 3
0
 public SoundDevice[] GetDevices()
 {
     uint numDevices = MMInterop.waveInGetNumDevs();
      List<SoundDevice> devices = new List<SoundDevice>((int)numDevices);
      for (uint i = 0; i < numDevices; i++) {
     // Get device capabilities
     MMInterop.WAVEINCAPS caps = new MMInterop.WAVEINCAPS();
     int mmr = MMInterop.waveInGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
     if (mmr == MMInterop.MMSYSERR_NODRIVER) {
        // No device driver is present.
        continue;
     }
     if (mmr != 0) {
        throw new SoundException("waveInGetDevCaps", mmr);
     }
     // Compare device name to loopback device names to see if
     // it is a loopback device
     bool isLoopback = false;
     foreach (string loopbackName in loopbackDeviceNames) {
        if (loopbackName.Equals(caps.szPname)) {
           isLoopback = true;
           break;
        }
     }
     SoundDevice device = new SoundDevice(i.ToString(), caps.szPname, isLoopback);
     devices.Add(device);
      }
      return devices.ToArray();
 }
Exemplo n.º 4
0
 public SoundFormat[] GetDeviceFormats(string deviceId)
 {
     if (string.IsNullOrEmpty(deviceId)) {
     throw new ArgumentNullException("deviceId");
      }
      uint uintId;
      if (!uint.TryParse(deviceId, out uintId)) {
     throw new ArgumentException("deviceId");
      }
      uint nDevice = MMInterop.waveInGetNumDevs();
      if (uintId <= nDevice - 1) {
     MMInterop.WAVEINCAPS caps = new MMInterop.WAVEINCAPS();
     int mmr = MMInterop.waveInGetDevCaps(uintId, ref caps, (uint)Marshal.SizeOf(caps));
     if (mmr != 0) {
        throw new SoundException("waveInGetDevCaps", mmr);
     }
     return Util.WaveFormatToSoundFormats((MMInterop.WaveFormat)caps.dwFormats);
      }
      throw new SoundException("Device not found.");
 }