public override bool MusicDeliver(PluginMusicDeliveryArgs args) { if (_client == null) { return false; } if (_providerConverted == null) { _volumeProvider = new VolumeSource(args.Source.ChangeSampleRate(48000).ToSampleSource()); _providerConverted = new BufferSource(_volumeProvider.ToWaveSource(16), _volumeProvider.WaveFormat.BytesPerSecond * 4); } _volumeProvider.Volume = MusicPlayer.Current.Volume; byte[] buffer = new byte[_volumeProvider.WaveFormat.BytesPerSecond]; int byteCount = _providerConverted.Read(buffer, 0, buffer.Length); if (byteCount > 0) { _voiceClient?.Send(buffer, 0, byteCount); } return 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; } }
public void Open(string filename) { CleanupPlayback(); var source = CodecFactory.Instance.GetCodec(filename); volumeSource = new VolumeSource(source); equalizer = Equalizer.Create10BandEqualizer(volumeSource); finalSource = equalizer .ToStereo() .ChangeSampleRate(44100) .AppendSource(Equalizer.Create10BandEqualizer, out equalizer) .ToWaveSource(16); if (WasapiOut.IsSupportedOnCurrentPlatform) soundOut = new WasapiOut() { Latency = 100, Device = device }; else soundOut = new DirectSoundOut(); soundOut.Initialize(finalSource); soundOut.Volume = deviceVolume; if (this.OpenCompleted != null) this.OpenCompleted(this, new EventArgs()); }