public void ChangeAudioDevice(string deviceName = null) { if (CurrentDeviceName == deviceName && ApplicationDevice != null) { return; } var playbackDevices = DirectSound.GetDevices(); // Use default device. Guid driverGuid = Guid.Empty; foreach (var device in playbackDevices) { // Pick specific device for the plaback. if (string.Compare(device.Description, deviceName, true) == 0) { driverGuid = device.DriverGuid; } } if (ApplicationDevice != null) { ApplicationDevice.Dispose(); ApplicationDevice = null; } // Create and set the sound device. ApplicationDevice = new DirectSound(driverGuid); SpeakerConfiguration speakerSet; SpeakerGeometry geometry; ApplicationDevice.GetSpeakerConfiguration(out speakerSet, out geometry); ApplicationDevice.SetCooperativeLevel(_Handle, CooperativeLevel.Normal); CurrentDeviceName = deviceName; }
private void CleanupResources() { if (_directSoundNotify != null) { _directSoundNotify.Dispose(); _directSoundNotify = null; } if (_secondaryBuffer != null) { _secondaryBuffer.Stop(); _secondaryBuffer.Dispose(); _secondaryBuffer = null; } if (_primaryBuffer != null) { _primaryBuffer.Stop(); _primaryBuffer.Dispose(); _primaryBuffer = null; } if (_directSound != null) { _directSound.Dispose(); _directSound = null; } _isInitialized = false; }
public void Destroy() { if (directSound != null) { directSound.Dispose(); } }
/// <summary> /// Disposes of any directsound resources /// </summary> public static void Shutdown() { foreach (SecondarySoundBuffer b in soundBuffers) { b.Dispose(); } soundBuffers.Clear(); device.Dispose(); }
private void ShutdownDirectSound() { // Release the primary sound buffer pointer. _PrimaryBuffer?.Dispose(); _PrimaryBuffer = null; // Release the direct sound interface pointer. _DirectSound?.Dispose(); _DirectSound = null; }
public void Dispose() { isInitialized = false; Stop(); buffer.Dispose(); buffer = null; _SoundDevice.Dispose(); _SoundDevice = null; GC.Collect(); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _directSound.Dispose(); } _disposed = true; } }
public void Dispose() { if (_disposed) { return; } _device.Dispose(); _device = null; _disposed = true; }
public void shutdownAndDispose() { soundStreamer.shutdown(); // blocks soundStreamerThread.Join(); secondarySoundBuffer.Dispose(); primarySoundBuffer.Dispose(); directSound.Dispose(); directSound = null; }
protected virtual void Dispose(bool disposing) { if (!_disposed && disposing) { _soundBuffer?.Stop(); _soundBuffer?.Dispose(); _primarySoundBuffer?.Dispose(); _directSound?.Dispose(); _disposed = true; } }
/// <summary> /// Disposes of the current sound buffer and device. /// </summary> protected void DestroyDirectSound() { if (_secondaryBuffer != null) { _secondaryBuffer.Dispose(); _secondaryBuffer = null; } if (_directSound != null) { _directSound.Dispose(); _directSound = null; } _isPlaying = false; }
private void ShutdownDirectSound() { // Release the listener interface. _Listener?.Dispose(); _Listener = null; // Release the 3D Secondary Sound Buffer. _3DSecondarySoundBuffer?.Dispose(); _3DSecondarySoundBuffer = null; // Release the primary sound buffer pointer. _PrimaryBuffer?.Dispose(); _PrimaryBuffer = null; // Release the direct sound interface pointer. _DirectSound?.Dispose(); _DirectSound = null; }
public void Destroy() { if (sBuffer != null) { sBuffer.Dispose(); } if (pBuffer != null) { pBuffer.Dispose(); } if (device != null) { device.Dispose(); } }
public void Dispose() { if (!_disposed) { _disposed = true; if (_waitThread != null && _waitThread.IsAlive) { _soundBuffer.Stop(); _waitThread.Interrupt(); _waitThread.Join(); } _outputDevice.Dispose(); } }
void ShutdownDirectSound() { // Release the primary sound buffer pointer. if (_PrimaryBuffer != null) { _PrimaryBuffer.Dispose(); _PrimaryBuffer = null; } // Release the direct sound interface pointer. if (_DirectSound != null) { _DirectSound.Dispose(); _DirectSound = null; } }
protected virtual void Dispose(bool safe) { if (safe) { if (audioBuffer != null) { audioBuffer.Dispose(); audioBuffer = null; } if (directSound != null) { directSound.Dispose(); directSound = null; } } }
public void Dispose() { Stop(); try { if (_SoundDevice != null) { _SoundDevice.Dispose(); } _SoundDevice = null; // if (buffer != null) // buffer.Dispose(); buffer = null; } catch { } GC.Collect(); }
protected virtual void Dispose(bool disposing) { if (!IsDisposed) { foreach (SecondarySoundBuffer b in cache.Values) { if (b != null) { b.Stop(); b.Dispose(); } } cache = null; dSound?.Dispose(); dSound = null; IsDisposed = true; } }
public void Shutdown() { IsPaused = true; if (buffer != null && buffer.Disposed & !IsRendering) { try { buffer.Stop(); } catch { return; } } while (IsRendering) { } buffer.Dispose(); _SoundDevice.Dispose(); if (RECODER.IsRecording) { RECODER.Stop(); } }
void NotifyThread() { var temp = new byte[mNotifySize]; int offset = 0; try { while (isRunning) { mNotificationEvent.WaitOne(); int playpos = scdBuffer.CurrentPlayPosition; //读指针(读取数据开端) int wrpos = scdBuffer.CurrentWritePosition; // 写指针(读取数据结尾) //while (PlayBuf.Count < mNotifySize) ; if (playBuf.Count >= mNotifySize) { playBuf.CopyTo(0, temp, 0, mNotifySize); playBuf.RemoveRange(0, mNotifySize); scdBuffer.Write(temp, 0, mNotifySize, offset * mNotifySize, LockFlags.None); // App.log.InfoFormat("声音....{0},{1},{2}", playpos, wrpos, playBuf.Count); } else { Array.Clear(temp, 0, temp.Length); scdBuffer.Write(temp, 0, mNotifySize, offset * mNotifySize, LockFlags.None); App.log.InfoFormat("声音数据不连续....{0},{1},{2}", playpos, wrpos, playBuf.Count); } scdBuffer.Play(0, PlayFlags.Looping); Console.WriteLine("Second: " + DateTime.Now.Second); offset = (offset + 1) % cNotifyNum; } } catch (ThreadAbortException) { device.Dispose(); mNotificationEvent.Dispose(); } }
private void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { FMODEX.RESULT result; foreach (var buffer in sounds.Values) { buffer.Buffer.Dispose(); } sounds.Clear(); soundDevice.Dispose(); result = system.close(); CheckError(result); result = system.release(); CheckError(result); SoundMasterControl.Instance.SeVolumeChanged -= Instance_SeVolumeChanged; } } disposed = true; }
public static void cleanUp() { DSBListener.Dispose(); primaryBuffer.Dispose(); objDS.Dispose(); }
public void Close() { lock (locker) { try { //Video if (thread_v != null) { IsAborted = true; playing_v.Set(); //Снимаем с паузы PlayingLoop, чтоб там сработала проверка на IsAborted processing.WaitOne(); //Ждем, пока обработается текущий кадр, если его считывание еще не закончилось thread_v.Join(); //Дожидаемся окончания работы PlayingLoop thread_v = null; } if (BitmapSource != null) { BitmapSource = null; } if (VBuffer != IntPtr.Zero) { if (IsInterop) { UnmapViewOfFile(VBuffer); } else { Marshal.FreeHGlobal(VBuffer); } VBuffer = IntPtr.Zero; } if (MemSection != IntPtr.Zero) { CloseHandle(MemSection); MemSection = IntPtr.Zero; } //Audio if (thread_a != null) { IsAborted = true; playing_a.Set(); thread_a.Join(); thread_a = null; } if (AudioBuffer != null) { AudioBuffer.Dispose(); AudioBuffer = null; } if (AudioDevice != null) { AudioDevice.Dispose(); AudioDevice = null; } } catch (Exception) { IsError = true; throw; } finally { if (h.IsAllocated) { h.Free(); } AdjustMediaTimer(0); UnloadAviSynth(); } } }