Exemplo n.º 1
0
        public static string GetDeviceName(int device)
        {
            var caps = new WaveApi.WAVEOUTCAPS();

            WaveApi.waveOutGetDevCaps((IntPtr)device, out caps, Marshal.SizeOf(caps));
            return(caps.szPname);
        }
 public static IEnumerable<string> GetDevices()
 {
     var count = WaveApi.waveOutGetNumDevs();
     for (var index = 0; index < count; index++)
     {
         var caps = new WaveApi.WAVEOUTCAPS();
         WaveApi.waveOutGetDevCaps((IntPtr)index, out caps, Marshal.SizeOf(caps));
         yield return caps.szPname;
     }
 }
Exemplo n.º 3
0
        void Play(double volume)
        {
            try
            {
                var hWaveOut = IntPtr.Zero;

                unsafe
                {
                    fixed(WaveApi.WAVEHDR *pHeader = &_header)
                    {
                        _waveOutProc = WaveOutProc;

                        Check(() => WaveApi.waveOutOpen(out hWaveOut, (IntPtr)(_device), ref _format, _waveOutProc, IntPtr.Zero, 0x30000));
                        Check(() => WaveApi.waveOutPrepareHeader(hWaveOut, ref _header, Marshal.SizeOf(_header)));
                        var monoVolume   = (int)(0xFFFF * volume) & 0xFFFF;
                        var stereoVolume = (monoVolume << 16) + monoVolume;
                        var result       = WaveApi.waveOutSetVolume(hWaveOut, stereoVolume);

                        if (_semaphoreInner.CurrentCount == 0)
                        {
                            Check(() => WaveApi.waveOutWrite(hWaveOut, ref _header, Marshal.SizeOf(_header)));

                            _semaphoreInner.Wait();
                        }

                        Check(() => WaveApi.waveOutReset(hWaveOut));
                        Check(() => WaveApi.waveOutUnprepareHeader(hWaveOut, ref _header, Marshal.SizeOf(_header)));
                    }
                }
                Check(() => WaveApi.waveOutClose(hWaveOut));
            }
            catch (WaveException)
            {
            }

            Marshal.FreeHGlobal(_hGlobal);

            _semaphoreOuter.Release();
        }
        public static int GetDeviceIndex(string device)
        {
            var count = WaveApi.waveOutGetNumDevs();

            var index = 0;
            var found = false;
            while (index < count && !found)
            {
                var caps = new WaveApi.WAVEOUTCAPS();
                WaveApi.waveOutGetDevCaps((IntPtr)index, out caps, Marshal.SizeOf(caps));

                if (caps.szPname == device)
                {
                    found = true;
                }
                else
                {
                    index++;
                }
            }

            return found ? index : -1;
        }