public override void Dispose() { mLoop = false; mVoice.Stop(); mDisposing = true; }
public override void Play(AudioBuffer buffer) { _xa2Buffer = (XAudio2AudioBuffer)buffer; _channelCount = GetChannelCount(_xa2Buffer.Format); _emitter.ChannelCount = _channelCount; if ((_channelCount > 1 && !_stereoState) || (_channelCount == 1 && _stereoState)) { float volume = _sourceVoice.Volume; _sourceVoice.DestroyVoice(); _sourceVoice.Dispose(); WaveFormat waveFormat = new WaveFormat(_xa2Buffer.Frequency, GetChannelCount(_xa2Buffer.Format)); _sourceVoice = new SourceVoice(_engine.XAudio2, waveFormat, VoiceFlags.None, maxFrequencyRatio: 2.0f); _sourceVoice.SetVolume(volume); _emitter.ChannelAzimuths = new[] { 0.0f }; _dspSettings = new DspSettings(_channelCount, 2); UpdateSourcePosition(); _stereoState = _channelCount == 2; } if (_sourcePositionDirty) { UpdateSourcePosition(); _sourcePositionDirty = false; } _audioBuffer.Stream = _xa2Buffer.DataStream; _audioBuffer.AudioBytes = _xa2Buffer.SizeInBytes; _audioBuffer.Flags = BufferFlags.EndOfStream; _sourceVoice.Stop(); _sourceVoice.FlushSourceBuffers(); _sourceVoice.SubmitSourceBuffer(_audioBuffer, null); _sourceVoice.Start(); }
public override void Dispose(bool disposing) { if (disposing) { if (sourceVoice != null) { sourceVoice.FlushSourceBuffers(); sourceVoice.Stop(); sourceVoice.Dispose(); sourceVoice = null; } if (xAudioBuffer != null) { xAudioBuffer.Stream.Dispose(); xAudioBuffer.Stream = null; xAudioBuffer = null; } if (xAudio != null) { xAudio.StopEngine(); xAudio.Dispose(); xAudio = null; } } }
public void Stop() { sourceVoice.FlushSourceBuffers(); sourceVoice.Stop(); isMute = true; }
public void UpdateChange(ISoundFactory factory) { if (currentSound != emitter.Sound) { // Changed: disposeSound(); } if (buffer == null && emitter.Sound != null) { loadSound(factory); currentSound = emitter.Sound; } if (emitter.Playing && !oldPlaying) { loadSound(factory); sourceVoice.SubmitSourceBuffer(buffer); sourceVoice.Start(); } else if (!emitter.Playing && oldPlaying) { sourceVoice.Stop(); sourceVoice.FlushSourceBuffers(); } }
private void Pause() { if (playerState == PlayerState.Playing) { sourceVoice.Stop(); SetPlayerState(PlayerState.Paused); } }
private void PlatformPause() { if (_voice != null && SoundEffect.MasterVoice != null) { _voice.Stop(); } _paused = true; }
private void PlatformPause() { if (_voice != null) { _voice.Stop(); } _paused = true; }
public void Dispose() { if (_voice != null && _voice.IsDisposed == false) { _voice.Stop(); _voice.FlushSourceBuffers(); _voice.DestroyVoice(); _voice.Dispose(); } }
//check voice status private void Check() { while (Voice.State.BuffersQueued > 0) { Thread.Sleep(10); } _voice.Stop(); _voice.FlushSourceBuffers(); isPlaying = false; Stopped?.Invoke(this); }
public void Flush() { m_cueId = new MyCueId(MyStringHash.NullOrEmpty); m_voice.Stop(); m_voice.FlushSourceBuffers(); DisposeWaves(); m_isPlaying = false; m_isPaused = false; m_isLoopable = false; m_currentDescriptor = null; }
static void Pause(bool flag) { if (flag) { sourceVoice.Stop(); } else { sourceVoice.Start(); } playing = !flag; }
public void Flush() { m_cueId = new MyCueId(MyStringHash.NullOrEmpty); m_voice.Stop(); m_voice.FlushSourceBuffers(); for (int i = 0; i < m_loopBuffers.Length; i++) { m_loopBuffers[i] = null; } m_isPlaying = false; m_isPaused = false; m_isLoopable = false; m_currentDescriptor = null; }
//check voice status private void Check() { try { while (Voice.State.BuffersQueued > 0) { Thread.Sleep(10); } _voice.Stop(); Stopped.Invoke(this); } catch { } }
public void Stop() { if (_voice != null) { _voice.Stop(); } }
public override void Stop() { if (SourceVoice != null) { SourceVoice.Stop(); } }
public void Clear() { //flush buffers SourceVoice.FlushSourceBuffers(); while (SourceVoice.State.BuffersQueued > 0) { SourceVoice.FlushSourceBuffers(); } SourceVoice.FlushSourceBuffers(); //stop sound SourceVoice.Stop(XAudio2.CommitNow); var buffers = _audioBuffers.ToArray(); _audioBuffers.Clear(); //dispose buffers foreach (var buffer in buffers) { buffer.Value.Stream.Dispose(); } //flush buffers SourceVoice.FlushSourceBuffers(); while (SourceVoice.State.BuffersQueued > 0) { SourceVoice.FlushSourceBuffers(); } }
void CloseDevice() { _sourceVoice?.Stop(PlayFlags.None, XAUDIO2_COMMIT_NOW); _sourceVoice?.FlushSourceBuffers(); _sourceVoice?.DestroyVoice(); _sourceVoice?.Dispose(); _xaudio2?.StopEngine(); _masteringVoice?.DestroyVoice(); _masteringVoice?.Dispose(); _xaudio2?.Dispose(); _sourceVoice = null; _masteringVoice = null; _xaudio2 = null; //if (_hidden.handle.IsAllocated) //{ // _hidden.handle.Free(); // _hidden.device = IntPtr.Zero; //} if (_hidden.mixbuf != null) { Marshal.FreeHGlobal((IntPtr)_hidden.mixbuf); _hidden.mixbuf = null; } _dev = null; }
// ReSharper disable once UnusedParameter.Local private void PlayImpl(string soundName, double balance, double volume) { var soundStream = GetSoundStream(soundName); if (soundStream == null) { return; } var stream = new WaveStream(soundStream); var voice = new SourceVoice(_audioDevice, stream.Format) { Volume = (float)volume }; var buf = new AudioBuffer { AudioData = stream, AudioBytes = (int)stream.Length }; voice.SubmitSourceBuffer(buf); voice.Start(); // This does not work, need matrix http://xboxforums.create.msdn.com/forums/t/75836.aspx //voice.SetChannelVolumes(2, new[] {(float) (balance <= 0 ? 1 : balance), (float) (balance >= 0 ? 1 : -balance)}); voice.BufferEnd += (sender, args) => _playerThreadDispatcher.BeginInvoke((Action)(() => { voice.Stop(); buf.Dispose(); voice.Dispose(); stream.Dispose(); })); }
public static void Stop() { Playing = false; var reg = AtmelContext.RAM[AtmelIO.OCR2B] as ObservableRegister; reg.OnRegisterChanged -= reg_OnRegisterChanged; SourceVoice.Stop(); }
public void srcVoice_BufferStart(object sender, ContextEventArgs e) { byte[] data = GenPPM(); ms.SetLength(0); ms.Write(data, 0, data.Length); ms.Position = 0; try { srcVoice.SubmitSourceBuffer(buffer); srcVoice.Start(); } catch { buffer.Flags = SlimDX.XAudio2.BufferFlags.EndOfStream; srcVoice.Stop(); } }
protected override void StopNativeMusic() { isPlaying = false; if (source == null) { return; } source.Stop(); source.FlushSourceBuffers(); }
/// <summary> /// Pauses the playback of the current instance. /// </summary> /// <exception cref="ObjectDisposedException">Is thrown if the current instance was already disposed.</exception> public void Pause() { if (IsDisposed) { throw new ObjectDisposedException(this.GetType().FullName); } voice.Stop(); paused = true; }
/// <summary> /// Stops audio playback. /// </summary> public void Stop() { if (!_isPlaying) { return; } if (IsSourceVoiceValid) { _sourceVoice.Stop(); } _isPlaying = false; }
protected override void StopNativeVideo() { isPlaying = false; source.Stop(); source.FlushSourceBuffers(); if (surface != null) { surface.IsActive = false; } surface = null; video.Stop(); }
/// <summary> /// Plays the audio. /// </summary> /// <param name="stop">If true, will stop the sound and return its position to 0 before playing it. Passing false will have the effect of resuming the sound from the last position it was stopped at.</param> /// <param name="loop">Whether or not to loop the sound.</param> public void play(bool stop, bool loop) { this.looping = loop; isInitializingPlayback = true; if (loop) { buffer.LoopCount = AudioBuffer.LoopInfinite; } // We'll start the buffer from the beginning if we've never played this buffer before so that the sound can be loaded. // Otherwise, the sound might start from a random position in the buffer. if (stop || hasNeverPlayed) { hasNeverPlayed = false; voice.Stop(); voice.FlushSourceBuffers(); buffer.Stream.Position = 0; voice.SubmitSourceBuffer(buffer, null); } voice.Start(); isStopped = false; isInitializingPlayback = false; }
public override void Dispose() { if (InvokeRequired) { Invoke(new DisposeDelegate(Dispose)); return; } while (mReadingData) { Thread.Sleep(1); } mIsDisposed = true; mVoice.FlushSourceBuffers(); Thread.Sleep(1); mVoice.Stop(); //w.BaseStream.Dispose(); try { mVoice.Dispose(); } catch (Exception e) { System.Diagnostics.Debug.Print("Caught exception {0}.\n{1}", e.GetType(), e.Message); } foreach (var b in buffer) { b.buffer.Dispose(); } System.Diagnostics.Debug.Print("Disposed streaming buffer {0}.", thisBufferIndex); }
public void Stop() { if (_loopForever == true) { if (_singleSourceVoice != null && _isPlaying) { _singleSourceVoice.Stop(); } _isPlaying = false; _isFading = false; } else { throw new Exception("Cannot stop overlapped audio."); } }
public void StopImmediate() { if (immediateVoice != null) { immediateVoice.Stop(); immediateVoice.FlushSourceBuffers(); immediateVoice.BufferEnd -= ImmediateVoice_BufferEnd; immediateVoice.DestroyVoice(); immediateVoice.Dispose(); immediateVoice = null; Utilities.FreeMemory(immediateAudioBuffer.AudioDataPointer); immediateAudioBuffer = null; immediateDonePlaying = true; } }
public void Say(string speech, float pan = 0) { Task.Run(async() => { if (currentSpeechVoice != null) { while (Math.Abs(currentSpeechVoice.Volume) > 0.001f) { currentSpeechVoice.SetVolume(MathHelper.Clamp(currentSpeechVoice.Volume - 0.00005f, 0f, 1f)); } currentSpeechVoice.Stop(); } _speechSynthesizer.Voice = SpeechSynthesizer.AllVoices.First(p => p.Gender == VoiceGender.Female); var stream = await _speechSynthesizer.SynthesizeTextToStreamAsync(speech); var c = new Cue(this, AudioChannels.Synth, stream.AsStreamForRead()); currentSpeechVoice = c.Start(pan); }); }