public void Dispose() { if (_thread != null) { try { _isComplete = true; if (_wave != IntPtr.Zero) { WindowsMultimedia.waveOutReset(_wave); } _thread.Join(); _fillDelegate = null; FreeBufferList(); if (_wave != IntPtr.Zero) { WindowsMultimedia.waveOutClose(_wave); } } finally { _thread = null; _wave = IntPtr.Zero; } } GC.SuppressFinalize(this); }
private void Release() { FreeAllBuffers(); if (_wave != IntPtr.Zero) { WindowsMultimedia.waveInClose(_wave); _wave = IntPtr.Zero; } }
public bool AddBuffer() { lock (this) { _event.Reset(); _isEnable = (WindowsMultimedia.waveInAddBuffer(_wave, ref _header, Marshal.SizeOf(_header)) == WindowsMultimedia.MMSYSERR_NOERROR); return(_isEnable); } }
public WaveOut(int device, WaveFormat format, int bufferSize, int bufferCount, BufferFillEventHandler fillProc) { _isZero = (format.wBitsPerSample == 8 ? (byte)128 : (byte)0); _fillDelegate = fillProc; Helper.Try(WindowsMultimedia.waveOutOpen(out _wave, device, format, _bufferDelegate, 0, WindowsMultimedia.CALLBACK_FUNCTION)); AllocateBufferList(bufferSize, bufferCount); _thread = new Thread(new ThreadStart(Thread)); _thread.Start(); }
public Buffer(IntPtr waveHandle, int size) { _wave = waveHandle; _headerHandle = GCHandle.Alloc(_header, GCHandleType.Pinned); _header.dwUser = (IntPtr)GCHandle.Alloc(this); _headerData = new byte[size]; _headerDataHandle = GCHandle.Alloc(_headerData, GCHandleType.Pinned); _header.lpData = _headerDataHandle.AddrOfPinnedObject(); _header.dwBufferLength = size; Helper.Try(WindowsMultimedia.waveInPrepareHeader(_wave, ref _header, Marshal.SizeOf(_header))); }
private void WorkerThread(object start) { if (BehaviorVector[(int)BehaviorVectorMask.DispatchOnWorkerThread]) { _dispatchOnWorkerThread = true; } WaveInfo = ((Func <IWaveInfo>)start)(); var grabber = new Grabber(WaveInfo, _dispatchOnWorkerThread); OnEnterWorkerThread(); try { var format = new WaveFormat(44100, 16, _device.Channels); int bufferSize = (_device.Channels == 1 ? 8192 : 16384); int buffers = 2; Helper.Try(WindowsMultimedia.waveInOpen(out _wave, _device.Device, format, _bufferDelegate, 0, WindowsMultimedia.CALLBACK_FUNCTION)); AllocateAllBuffers(bufferSize, buffers); Helper.Try(WindowsMultimedia.waveInStart(_wave)); // if (_dispatchOnWorkerThread) { Dispatcher.Run(); //while (!WaitHandle.WaitAll(new WaitHandle[] { _stopSignal }, 10, true)) while (!_stopEvent.WaitOne(10, true)) { AdvanceBuffer(); grabber.Buffer(_currentBuffer.Data, _currentBuffer.Size); _currentBuffer.AddBuffer(); Dispatcher.Run(); } Dispatcher.ExitAllFrames(); } else { while (!_stopEvent.WaitOne(0, true)) { AdvanceBuffer(); grabber.Buffer(_currentBuffer.Data, _currentBuffer.Size); _currentBuffer.AddBuffer(); } } } catch (Exception ex) { Debug.WriteLine(ex); throw; } finally { // guaranteed exit OnExitWorkerThread(); } }
public static void Run() { Sys.Execution.Shutdown(); WindowsMultimedia wm = new WindowsMultimedia(); wm.EndEnhancedResolution(); // Release all contexts. VixenSystem.Contexts.ReleaseContexts(); // Stop all output devices. VixenSystem.OutputDeviceManagement.StopAll(); }
// No state needed for this, so going to make it static. public static void Run() { WindowsMultimedia wm = new WindowsMultimedia(); wm.BeginEnhancedResolution(); // Enabled/disabled list is going to be an opt-in list of disabled devices // so that new devices don't need to be added to it in order to be enabled. IEnumerable<IOutputDevice> enabledDevices = VixenSystem.OutputDeviceManagement.Devices.Except(VixenSystem.SystemConfig.DisabledDevices); VixenSystem.OutputDeviceManagement.StartOnly(enabledDevices); Sys.Execution.Startup(); }
public static void Run() { Sys.Execution.Shutdown(); WindowsMultimedia wm = new WindowsMultimedia(); wm.EndEnhancedResolution(); // Release all contexts. VixenSystem.Contexts.ReleaseContexts(); // Stop all output devices. VixenSystem.OutputDeviceManagement.StopAll(); }
// No state needed for this, so going to make it static. static public void Run() { WindowsMultimedia wm = new WindowsMultimedia(); wm.BeginEnhancedResolution(); // Enabled/disabled list is going to be an opt-in list of disabled devices // so that new devices don't need to be added to it in order to be enabled. IEnumerable <IOutputDevice> enabledDevices = VixenSystem.OutputDeviceManagement.Devices.Except(VixenSystem.SystemConfig.DisabledDevices); VixenSystem.OutputDeviceManagement.StartOnly(enabledDevices); Sys.Execution.Startup(); }
public void Dispose() { if (_header.lpData != IntPtr.Zero) { WindowsMultimedia.waveInUnprepareHeader(_wave, ref _header, Marshal.SizeOf(_header)); _headerHandle.Free(); _header.lpData = IntPtr.Zero; } _event.Close(); if (_headerDataHandle.IsAllocated) { _headerDataHandle.Free(); } GC.SuppressFinalize(this); }
public static void Try(int err) { if (err != WindowsMultimedia.MMSYSERR_NOERROR) { var text = new byte[1000]; if (WindowsMultimedia.waveInGetErrorText(err, text, text.Length) != 0) { throw new Exception(); } int index; for (index = 0; (index < text.Length) && (text[index] != 0); index++) { } string errorText = UTF8Encoding.Default.GetString(text, 0, index); throw new Exception(errorText); } }
private void WaitForAllBuffers() { if (_wave != IntPtr.Zero) { WindowsMultimedia.waveInReset(_wave); } if (_buffers == null) { return; } var buffer = _buffers; while (buffer.Next != _buffers) { buffer.WaitFor(); buffer = buffer.Next; } }
public static int GetDevices() { return(WindowsMultimedia.waveInGetNumDevs()); }