/// <summary> /// Plays the sound. /// </summary> /// <param name="source">The WaveSource.</param> private void Play(IWaveSource source) { Stop(); var panSource = new PanSource(source); _panSource = panSource; _directSoundOut.Initialize(panSource.ToWaveSource()); _directSoundOut.Play(); }
public bool OpenFile(string filename, Func<IWaveSource, IWaveSource> oninitcallback) { if (String.IsNullOrWhiteSpace(filename)) throw new ArgumentException("filename"); try { var source = CodecFactory.Instance.GetCodec(filename); source = new LoopStream(source); (source as LoopStream).EnableLoop = false; if (source.WaveFormat.Channels == 1) source = new MonoToStereoSource(source).ToWaveSource(16); _panSource = new PanSource(source) { Pan = this.Pan }; var _notification = new SimpleNotificationSource(_panSource); _notification.DataRead += OnNotification; source = _notification.ToWaveSource(16); //source = new BufferSource(source, source.WaveFormat.BytesPerSecond * 2); _source = source; if (oninitcallback != null) SoundOutManager.Initialize(oninitcallback(source)); else SoundOutManager.Initialize(source); } catch (Exception) { return false; } RaiseUpdated(); return true; }
public void Stop() { SoundOutManager.Stop(); _panSource = null; _source = null; RaiseUpdated(); }
/// <summary> /// Plays the wave source. /// </summary> /// <param name="waveSource">The WaveSource.</param> internal void Play(IWaveSource waveSource) { var panSource = new PanSource(waveSource); _panSource = panSource; _currentWaveSource = panSource.ToWaveSource(); _sourceVoice = StreamingSourceVoice.Create(_xaudio2, _currentWaveSource); StreamingSourceVoiceListener.Default.Add(_sourceVoice); _playbackState = PlaybackState.Playing; IsPlaying = true; if (PlaybackChanged != null) PlaybackChanged(this, EventArgs.Empty); }