Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        /// <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;
            }
        }
Exemplo n.º 3
0
        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());
        }