예제 #1
0
        /// <summary>
        /// Opens the audio device.
        /// </summary>
        /// <param name="deviceId">The device identifier.</param>
        /// <param name="format">The format.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="intanceHandle">The intance handle.</param>
        /// <param name="openFlags">The open flags.</param>
        /// <returns>The audio device handle</returns>
        /// <exception cref="TimeoutException">Occurs when the interop lock cannot be acquired.</exception>
        /// <exception cref="MmException">Occurs when the MME interop call fails</exception>
        public static IntPtr OpenAudioDevice(int deviceId, WaveFormat format, WaveCallback callback, IntPtr intanceHandle, WaveInOutOpenFlags openFlags)
        {
            if (deviceId < -1)
            {
                deviceId = -1;
            }
            var acquired = false;

            Monitor.TryEnter(SyncLock, LockTimeout, ref acquired);
            if (acquired == false)
            {
                throw new TimeoutException(TimeoutErrorMessage);
            }

            try
            {
                MmException.Try(
                    NativeMethods.waveOutOpen(out IntPtr hWaveOut, deviceId, format, callback, intanceHandle, openFlags),
                    nameof(NativeMethods.waveOutOpen));

                return(hWaveOut);
            }
            catch { throw; }
            finally { Monitor.Exit(SyncLock); }
        }
예제 #2
0
파일: WaveIn.cs 프로젝트: opcon/cscore
 /// <summary>
 /// Initializes a new instance of the <see cref="WaveIn"/> class.
 /// </summary>
 /// <param name="waveFormat">The default format to use. The final format must not equal the specified <paramref name="waveFormat"/>.</param>
 /// <exception cref="System.ArgumentNullException">waveFormat</exception>
 public WaveIn(WaveFormat waveFormat)
 {
     if (waveFormat == null)
         throw new ArgumentNullException("waveFormat");
     WaveFormat = waveFormat;
     _callback = Callback;
     RecordingState = RecordingState.Stopped;
     Device = WaveInDevice.DefaultDevice;
 }
예제 #3
0
파일: WaveOut.cs 프로젝트: hoangduit/cscore
        /// <summary>
        ///     Initializes a new instance of the <see cref="WaveOut" /> class.
        /// </summary>
        /// <param name="latency">Latency of the playback specified in milliseconds.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">latency must not be less or equal to zero.</exception>
        public WaveOut(int latency)
        {
            if (latency <= 0)
                throw new ArgumentOutOfRangeException("latency");

            _latency = latency;
            _callback = Callback;
            Device = WaveOutDevice.DefaultDevice;
            UseChannelMixingMatrices = true;
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaveIn"/> class.
 /// </summary>
 /// <param name="waveFormat">The default format to use. The final format must not equal the specified <paramref name="waveFormat"/>.</param>
 /// <exception cref="System.ArgumentNullException">waveFormat</exception>
 public WaveIn(WaveFormat waveFormat)
 {
     if (waveFormat == null)
     {
         throw new ArgumentNullException("waveFormat");
     }
     WaveFormat     = waveFormat;
     _callback      = Callback;
     RecordingState = RecordingState.Stopped;
     Device         = WaveInDevice.DefaultDevice;
 }
예제 #5
0
        public WaveInputPort(int deviceID, int channels, int sampleRate, int bitsPerSample, double latency)
            :base(deviceID, channels, sampleRate, bitsPerSample)
        {
            Latency = latency;

            // Calculate the sample size based on the latency
            SampleSize = (int)(Latency * PCMFormat.BytesPerSecond);
            SampleCount = (int)(1.0 / Latency);

            fCallbackMethod = new WaveCallback(this.DefaultAudioCallback);
        }
예제 #6
0
        public WaveOutputPort(int deviceID, WAVEFORMATEX wf)
        {
            fCallbackMethod = new WaveCallback(this.DefaultAudioCallback);

            DeviceHandle = null;
            DeviceID = deviceID;
            WaveFormat = wf;
            PCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf);
            
            Open();
        }
예제 #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="WaveOut" /> class.
        /// </summary>
        /// <param name="latency">Latency of the playback specified in milliseconds.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">latency must not be less or equal to zero.</exception>
        public WaveOut(int latency)
        {
            if (latency <= 0)
            {
                throw new ArgumentOutOfRangeException("latency");
            }

            _latency  = latency;
            _callback = Callback;
            Device    = WaveOutDevice.DefaultDevice;
            UseChannelMixingMatrices = true;
        }
예제 #8
0
        public WinMMAudioDevice(int deviceID, WAVEFORMATEX wf)
        {
            fCallbackMethod = new WaveCallback(this.DefaultAudioCallback);

            fDeviceHandle = IntPtr.Zero;
            fDeviceID = deviceID;
            fWaveFormat = wf;
            fPCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf);

            //if (callbackProc != null)
            //    fCallbackProcedure = callbackProc;
            //else
            //    fCallbackProcedure = DefaultAudioCallback;
        }
예제 #9
0
        /// <summary>
        /// Opens the audio device.
        /// </summary>
        /// <param name="deviceId">The device identifier.</param>
        /// <param name="format">The format.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="instanceHandle">The instance handle.</param>
        /// <param name="openFlags">The open flags.</param>
        /// <returns>The audio device handle.</returns>
        /// <exception cref="TimeoutException">Occurs when the interop lock cannot be acquired.</exception>
        /// <exception cref="LegacyAudioException">Occurs when the MME interop call fails.</exception>
        public static IntPtr OpenAudioDevice(int deviceId, WaveFormat format, WaveCallback callback, IntPtr instanceHandle, WaveInOutOpenFlags openFlags)
        {
            if (deviceId < -1)
            {
                throw new ArgumentException($"Invalid Device ID {deviceId}", nameof(deviceId));
            }
            if (!TryEnterDeviceOperation())
            {
                return(IntPtr.Zero);
            }

            try
            {
                LegacyAudioException.Try(
                    NativeMethods.OpenDevice(out var hWaveOut, deviceId, format, callback, instanceHandle, openFlags),
                    nameof(NativeMethods.OpenDevice));

                return(hWaveOut);
            }
            finally { Monitor.Exit(SyncLock); }
        }
 public static extern MmResult waveOutOpen(out IntPtr hWaveOut, IntPtr uDeviceID, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags dwFlags);
예제 #11
0
 public static extern MmResult waveInOpen(out IntPtr hWaveIn, int uDeviceID, WaveFormat lpFormat, WaveCallback dwCallback, int dwInstance, int dwFlags);
예제 #12
0
 public static extern MMSYSERROR waveInOpen(ref IntPtr phwi, 
     int uDeviceID,
     [In, MarshalAs(UnmanagedType.LPStruct)] WAVEFORMATEX pwfx, 
     WaveCallback dwCallback, 
     IntPtr dwInstance,
     WAVEOPENFLAGS openFlags);
예제 #13
0
 public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr uDeviceID, WaveFormatProvider lpFormat, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags dwFlags);
예제 #14
0
 public static extern int waveOutOpen(out IntPtr phwi, int deviceID, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, int dwFlags);
예제 #15
0
 public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr device, WaveFormat pwfx, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags fdwOpen);
예제 #16
0
 public static extern MmResult waveOutOpen(out IntPtr hWaveOut, IntPtr device, WaveFormat lpFormat, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags dwFlags);
예제 #17
0
 public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr device, WaveFormat pwfx, WaveCallback dwCallback, IntPtr dwInstance, WaveInOutOpenFlags fdwOpen);
예제 #18
0
 internal static extern MMResult waveOutOpen(out IntPtr hWaveOut, IntPtr uDeviceID, WaveFormat lpFormat,
     WaveCallback dwCallback, IntPtr dwInstance, uint dwFlags);
예제 #19
0
 public static extern MMSYSERROR waveOutOpen(ref IntPtr phwo, 
     int uDeviceID,
     [In, MarshalAs(UnmanagedType.LPStruct)]WAVEFORMATEX pwfx, 
     WaveCallback dwCallback,    // When using a callback function
     IntPtr dwInstance, 
     int openFlags);
예제 #20
0
 internal static extern MMResult waveOutOpen(out IntPtr hWaveOut, IntPtr uDeviceID, WaveFormat lpFormat,
                                             WaveCallback dwCallback, IntPtr dwInstance, uint dwFlags);
예제 #21
0
 public static extern MmResult waveInOpen(out IntPtr hWaveIn, IntPtr uDeviceID, WaveFormat lpFormat,
                                          WaveCallback dwCallback, IntPtr dwInstance, int dwFlags);