コード例 #1
0
        public IEnumerable <DeviceInfo> EnumerateDevices()
        {
            if (mode == Mode.Record)
            {
                uint count = waveInGetNumDevs();

                for (uint i = 0; i < count; ++i)
                {
                    WAVEINCAPS caps = new WAVEINCAPS();
                    if (waveInGetDevCaps(i, ref caps, 48) == 0)
                    {
                        yield return(new DeviceInfo()
                        {
                            index = (int)i, name = caps.szPname
                        });
                    }
                }
            }
            else if (mode == Mode.Play)
            {
                uint count = waveOutGetNumDevs();

                for (uint i = 0; i < count; ++i)
                {
                    WAVEOUTCAPS caps = new WAVEOUTCAPS();
                    if (waveOutGetDevCaps(i, ref caps, 48) == 0)
                    {
                        yield return(new DeviceInfo()
                        {
                            index = (int)i, name = caps.szPname
                        });
                    }
                }
            }
        }
コード例 #2
0
ファイル: WaveIn.cs プロジェクト: otac0n/winmm
        /// <summary>
        /// Retrieves the capabilities of a device.
        /// </summary>
        /// <param name="deviceId">The DeviceID for which to retrieve the capabilities.</param>
        /// <returns>The capabilities of the device.</returns>
        private static WaveInDeviceCaps GetDeviceCaps(int deviceId)
        {
            WAVEINCAPS wicaps = new WAVEINCAPS();

            NativeMethods.waveInGetDevCaps((IntPtr)deviceId, ref wicaps, Marshal.SizeOf(wicaps.GetType()));
            WaveInDeviceCaps caps = new WaveInDeviceCaps();

            caps.DeviceId      = (int)deviceId;
            caps.Channels      = wicaps.wChannels;
            caps.DriverVersion = (int)wicaps.vDriverVersion;
            caps.Manufacturer  = GetManufacturer(wicaps.wMid);
            caps.Name          = wicaps.szPname;
            caps.ProductId     = wicaps.wPid;

            return(caps);
        }
コード例 #3
0
ファイル: WaveNative.cs プロジェクト: wxsh/axStream
        //http://blogs.msdn.com/b/matthew_van_eerde/archive/2012/03/13/sample-how-to-enumerate-wavein-and-waveout-devices-on-your-system.aspx
        //http://www.codeproject.com/Articles/18685/Enumerating-Sound-Recording-Devices-Using-winmm-dl?fid=415295&df=90&mpp=10&noise=1&prof=True&sort=Position&view=Quick&spc=Relaxed&fr=11
        public static List <string> EnumInputDevices()
        {
            List <string> InputDeviceNames   = new List <string>();
            int           waveInDevicesCount = waveInGetNumDevs(); //get total

            if (waveInDevicesCount > 0)
            {
                for (int uDeviceID = 0; uDeviceID < waveInDevicesCount; uDeviceID++)
                {
                    WAVEINCAPS waveInCaps = new WAVEINCAPS();
                    waveInGetDevCaps(uDeviceID, ref waveInCaps, Marshal.SizeOf(typeof(WAVEINCAPS)));
                    string devnameandid = "Device ID " + uDeviceID + ": " + new string(waveInCaps.szPname);
                    InputDeviceNames.Add(devnameandid.Remove(devnameandid.IndexOf('\0')).Trim());
                }
            }
            return(InputDeviceNames);
        }
コード例 #4
0
        /// <summary>
        /// Gets the dev caps recording.
        /// </summary>
        /// <returns></returns>
        public static WAVEINCAPS[] GetDevCapsRecording()
        {
            var waveInDevicesCount = waveInGetNumDevs();

            if (waveInDevicesCount > 0)
            {
                var list = new WAVEINCAPS[waveInDevicesCount];
                for (var uDeviceID = 0; uDeviceID < waveInDevicesCount; uDeviceID++)
                {
                    var waveInCaps = new WAVEINCAPS();
                    waveInGetDevCaps(uDeviceID, ref waveInCaps, Marshal.SizeOf(typeof(WAVEINCAPS)));
                    list[uDeviceID] = waveInCaps;
                }
                return(list);
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: desla/AS
        static void Main(string[] args)
        {
            var deviceCount = waveOutGetNumDevs();
            Console.WriteLine("Найдено {0} устаройств вывода: ", deviceCount);
            for (var i = 0; i < deviceCount; ++i) {
                var wOutCaps = new WAVEOUTCAPS();
                waveOutGetDevCaps(new UIntPtr((uint)i), ref wOutCaps, (uint)Marshal.SizeOf(typeof(WAVEOUTCAPS)));
                Console.WriteLine("Имя:\"{0}\" Каналов:{1}", wOutCaps.SzPname, wOutCaps.WChannels);
            }

            Console.WriteLine();

            deviceCount = waveInGetNumDevs();
            Console.WriteLine("Найдено {0} устаройств ввода: ", deviceCount);
            for (var i = 0; i < deviceCount; ++i) {
                var wInCaps = new WAVEINCAPS();
                waveInGetDevCaps(new UIntPtr((uint)i), ref wInCaps, (uint)Marshal.SizeOf(typeof(WAVEOUTCAPS)));
                Console.WriteLine("Имя:\"{0}\" Каналов:{1}", wInCaps.SzPname, wInCaps.WChannels);
            }

            Console.WriteLine("\nДля выхода нажмите Enter.");
            Console.ReadLine();
        }
コード例 #6
0
ファイル: WaveIn.cs プロジェクト: avogelba/PWR
        /// <summary>Get the input device name from device id</summary>
        /// <param name="deviceId">device id</param>
        /// <param name="prodName">returns device name</param>
        /// <returns>MMSYSERR</returns>
        public MMSYSERR GetInputDeviceName(uint deviceId, ref string prodName)
        {
            WAVEINCAPS caps   = new WAVEINCAPS();
            MMSYSERR   result = waveInGetDevCaps(deviceId, out caps, (uint)Marshal.SizeOf(caps));

            if (result != MMSYSERR.NOERROR)
            {
                return(result);
            }
            prodName = new string(caps.szPname);
            if (prodName.Contains("(") && !(prodName.Contains(")")))
            {
                prodName = prodName.Substring(0, prodName.IndexOf("("));
            }
            else if (prodName.Contains(")"))
            {
                if (prodName.IndexOf(")") > 8)
                {
                    prodName = prodName.Substring(0, prodName.IndexOf(")") + 1);
                }
            }
            return(MMSYSERR.NOERROR);
        }
コード例 #7
0
ファイル: WaveNative.cs プロジェクト: llytvynenko/axStream
 public static extern int waveInGetDevCaps(int uDeviceID, ref WAVEINCAPS lpCaps, int uSize);
コード例 #8
0
 private static extern uint waveInGetDevCaps(uint uDeviceID, ref WAVEINCAPS pwic, uint cbwic);
コード例 #9
0
ファイル: Program.cs プロジェクト: desla/AS
 public static extern uint waveInGetDevCaps(UIntPtr hWaveIn, ref WAVEINCAPS pwic, uint cbwoc);
コード例 #10
0
 public static extern int waveInGetDevCaps(IntPtr uDeviceID, ref WAVEINCAPS pwic, uint cbwic);
コード例 #11
0
 public static extern uint waveInGetDevCaps(IntPtr deviceId, out WAVEINCAPS caps, int capsSize);
コード例 #12
0
ファイル: WaveIn.cs プロジェクト: master20151121/mmoments
			/// <summary>
			/// Preload the buffers and prepare them for recording.
			/// </summary>
			/// <param name="curDevice">Device to use for recording</param>
			/// <param name="hwnd">Handle to a message window that will receive
			/// audio messages.</param>
			/// <param name="maxRecordLength_ms">Maximum length of recording</param>
			/// <param name="bufferSize">Size of buffers to use for recording.  New
			/// buffers are added when needed until the maximum length is reached
			/// or the recording is stopped.</param>
			/// <returns>MMSYSERR.NOERROR if successful</returns>
			public Wave.MMSYSERR Preload(uint curDevice, IntPtr hwnd, int maxRecordLength_ms, int bufferSize)
			{
				// Do not allow recording to be interrupted
				if (m_recording)
					return Wave.MMSYSERR.ERROR;

				// If this file is already initialized then start over
				if (m_inited)
				{
					Stop();
					FreeWaveBuffers();
				}

				// Create an instance of WAVEINCAPS to check if our desired
				// format is supported
				WAVEINCAPS caps = new WAVEINCAPS();
				waveInGetDevCaps(0, caps, caps.Size);
				if ((caps.dwFormats & Wave.WAVE_FORMAT_1S16) == 0)
					return Wave.MMSYSERR.NOTSUPPORTED;

				// Initialize a WAVEFORMATEX structure specifying the desired
				// format
				m_wfmt = new Wave.WAVEFORMATEX();
				m_wfmt.wFormatTag = Wave.WAVEHDR.WAVE_FORMAT_PCM;
				m_wfmt.wBitsPerSample = 16;
				m_wfmt.nChannels = 2;
                m_wfmt.nSamplesPerSec = 44110;//11025;
				m_wfmt.nAvgBytesPerSec = (uint)(m_wfmt.nSamplesPerSec * m_wfmt.nChannels * (m_wfmt.wBitsPerSample / 8));
				m_wfmt.nBlockAlign = (ushort)(m_wfmt.wBitsPerSample * m_wfmt.nChannels / 8);

				// Attempt to open the specified device with the desired wave format
				Wave.MMSYSERR result = waveInOpen(ref m_hwi, curDevice, m_wfmt, hwnd, 0, Wave.CALLBACK_WINDOW);
				if (result != Wave.MMSYSERR.NOERROR)
					return result;

				if (bufferSize == 0)
					return Wave.MMSYSERR.ERROR;

				m_bufferSize = (uint)bufferSize;

				// Force the buffers to align to nBlockAlign
				if (m_bufferSize % m_wfmt.nBlockAlign != 0)
					m_bufferSize += m_wfmt.nBlockAlign - (m_bufferSize % m_wfmt.nBlockAlign);

				// Determine the number of buffers needed to record the maximum length
				m_maxDataLength = (uint)(m_wfmt.nAvgBytesPerSec * maxRecordLength_ms / 1000);
				m_numBlocks = (int)(m_maxDataLength / m_bufferSize);
				if (m_numBlocks * m_bufferSize < m_maxDataLength)
					m_numBlocks++;

				// Allocate the list of buffers
				m_whdr = new Wave.WAVEHDR[m_numBlocks + 1];

				// Allocate and initialize two buffers to start with
				m_whdr[0] = new Wave.WAVEHDR();
				m_whdr[1] = new Wave.WAVEHDR();

				result = InitBuffer(0);
				if (result != Wave.MMSYSERR.NOERROR)
					return result;

				result = InitBuffer(1);
				if (result != Wave.MMSYSERR.NOERROR)
					return result;

				m_curBlock = 0;
				m_inited = true;

				return Wave.MMSYSERR.NOERROR;
			}
コード例 #13
0
ファイル: WaveIn.cs プロジェクト: master20151121/mmoments
		/// <summary>
		/// Get the name of the specified recording device.
		/// </summary>
		/// <param name="deviceId">ID of the device</param>
		/// <param name="prodName">Destination string assigned the name</param>
		/// <returns>MMSYSERR.NOERROR if successful</returns>
		public Wave.MMSYSERR GetDeviceName(uint deviceId, ref string prodName)
		{
			WAVEINCAPS caps = new WAVEINCAPS();
			Wave.MMSYSERR result = waveInGetDevCaps(deviceId, caps, caps.Size);
			if (result != Wave.MMSYSERR.NOERROR)
				return result;

			prodName = caps.szPname;

			return Wave.MMSYSERR.NOERROR;
		}
コード例 #14
0
 public static extern uint waveInGetDevCaps(int index, ref WAVEINCAPS pwic, int cbwic);
コード例 #15
0
ファイル: WaveNative.cs プロジェクト: llytvynenko/axStream
 //http://blogs.msdn.com/b/matthew_van_eerde/archive/2012/03/13/sample-how-to-enumerate-wavein-and-waveout-devices-on-your-system.aspx
 //http://www.codeproject.com/Articles/18685/Enumerating-Sound-Recording-Devices-Using-winmm-dl?fid=415295&df=90&mpp=10&noise=1&prof=True&sort=Position&view=Quick&spc=Relaxed&fr=11
 public static List<string> EnumInputDevices()
 {
     List<string> InputDeviceNames = new List<string>();
     int waveInDevicesCount = waveInGetNumDevs(); //get total
     if (waveInDevicesCount > 0)
     {
         for (int uDeviceID = 0; uDeviceID < waveInDevicesCount; uDeviceID++)
         {
             WAVEINCAPS waveInCaps = new WAVEINCAPS();
             waveInGetDevCaps(uDeviceID, ref waveInCaps, Marshal.SizeOf(typeof(WAVEINCAPS)));
             string devnameandid = "Device ID " + uDeviceID + ": " + new string(waveInCaps.szPname);
             InputDeviceNames.Add(devnameandid.Remove(devnameandid.IndexOf('\0')).Trim());
         }
     }
     return InputDeviceNames;
 }
コード例 #16
0
ファイル: WaveNative.cs プロジェクト: wxsh/axStream
 public static extern int waveInGetDevCaps(int uDeviceID, ref WAVEINCAPS lpCaps, int uSize);
コード例 #17
0
 private static extern uint waveInGetDevCaps(int hwo, ref WAVEINCAPS pwic, /*uint*/ int cbwic);
コード例 #18
0
ファイル: MMInterop.cs プロジェクト: bspkrs/screenrecorder
 public static extern int waveInGetDevCaps(uint uDeviceID, ref WAVEINCAPS pwic, uint cbwic);
コード例 #19
0
ファイル: WaveIn.cs プロジェクト: avogelba/PWR
 private static extern MMSYSERR waveInGetDevCaps(uint uDeviceID, out WAVEINCAPS pwoc, uint cbwoc);