/// <summary> /// Initializes WasapiOut instance and prepares all resources for playback. /// Note that properties like <see cref="Device" />, <see cref="Latency" />,... won't affect WasapiOut after calling /// <see cref="Initialize" />. /// </summary> /// <param name="source">The source to prepare for playback.</param> public void Initialize(IWaveSource source) { CheckForInvalidThreadCall(); lock (_lockObj) { CheckForDisposed(); if (source == null) { throw new ArgumentNullException("source"); } if (PlaybackState != PlaybackState.Stopped) { throw new InvalidOperationException( "PlaybackState has to be Stopped. Call WasapiOut::Stop to stop the playback."); } _playbackThread.WaitForExit(); source = new InterruptDisposingChainSource(source); _volumeSource = new VolumeSource(source.ToSampleSource()); _source = _volumeSource.ToWaveSource(); CleanupResources(); InitializeInternal(); _isInitialized = true; } }
/// <summary> /// Initializes WasapiOut instance and prepares all resources for playback. /// Note that properties like <see cref="Device" />, <see cref="Latency" />,... won't affect WasapiOut after calling /// <see cref="Initialize" />. /// </summary> /// <param name="source">The source to prepare for playback.</param> public void Initialize(IWaveSource source) { CheckForInvalidThreadCall(); lock (_lockObj) { CheckForDisposed(); if (source == null) throw new ArgumentNullException("source"); if (PlaybackState != PlaybackState.Stopped) { throw new InvalidOperationException( "PlaybackState has to be Stopped. Call WasapiOut::Stop to stop the playback."); } _playbackThread.WaitForExit(); source = new InterruptDisposingChainSource(source); _volumeSource = new VolumeSource(source.ToSampleSource()); _source = _volumeSource.ToWaveSource(); CleanupResources(); InitializeInternal(); _isInitialized = true; } }