コード例 #1
0
ファイル: SoundInSource.cs プロジェクト: opcon/cscore
        /// <summary>
        /// Initializes a new instance of the <see cref="SoundInSource"/> class.
        /// </summary>
        /// <param name="soundIn">The soundIn which provides recorded data.</param>
        /// <param name="bufferSize">Size of the internal buffer in bytes.</param>
        /// <remarks>
        /// Note that soundIn has to be already initialized.
        /// Note that old data ("old" gets specified by the bufferSize) gets overridden. 
        /// For example, if the bufferSize is about 5 seconds big, data which got recorded 6 seconds ago, won't be available anymore.
        /// </remarks>
        public SoundInSource(ISoundIn soundIn, int bufferSize)
        {
            if (soundIn == null)
                throw new ArgumentNullException("soundIn");
            ThrowIfSoundInNotInitialized(soundIn);

            _buffer = new WriteableBufferingSource(soundIn.WaveFormat, bufferSize) {FillWithZeros = false};
            _soundIn = soundIn;
            _soundIn.DataAvailable += OnDataAvailable;
        }
コード例 #2
0
ファイル: SoundInSource.cs プロジェクト: CheViana/AudioLab
        /// <summary>
        /// Creates an new instance of SoundInSource with a default bufferSize of 5 seconds.
        /// </summary>
        /// <param name="soundIn">The soundIn which provides recorded data.</param>
        /// <param name="bufferSize">Size of the buffer in bytes.</param>
        /// <remarks>
        /// Note that soundIn has to be already initialized.
        /// Note that old data ("old" gets specified by the bufferSize) gets overridden. 
        /// For example, if the bufferSize is about 5 seconds big, data which got recorded 6 seconds ago, won't be available anymore.
        /// </remarks>
        public SoundInSource(ISoundIn soundIn, int bufferSize)
        {
            if (soundIn == null)
                throw new ArgumentNullException("soundIn");
            //bufferSize gets validated by WriteableBufferingSource

            _buffer = new WriteableBufferingSource(soundIn.WaveFormat, bufferSize);
            _buffer.FillWithZeros = false;
            _soundIn = soundIn;
            _soundIn.DataAvailable += OnDataAvailable;
        }
コード例 #3
0
ファイル: SoundInSource.cs プロジェクト: CheViana/AudioLab
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (SoundIn != null)
                {
                    SoundIn.DataAvailable -= OnDataAvailable;
                    _soundIn = null;
                }

                if (_buffer != null)
                {
                    _buffer.Dispose();
                    _buffer = null;
                }
            }
            _disposed = true;
        }
コード例 #4
0
ファイル: TorshifySongPlayer.cs プロジェクト: jmazouri/Picofy
        private void _session_MusicDeliver(object sender, MusicDeliveryEventArgs e)
        {
            int consumed = 0;

            lock (_lockObject)
            {
                if (_provider == null)
                {
                    _provider = new WriteableBufferingSource(new WaveFormat(e.Rate, 16, e.Channels, AudioEncoding.Pcm), (e.Rate * 2))
                    {
                        FillWithZeros = false
                    };

                    _waveOut.Stop();
                    _waveOut.Initialize(_provider);
                    _waveOut.Volume = _volume;
                }

                List<bool> results = MusicPlayer.Current.Plugins.Select(plugin => plugin.MusicDeliver(new PluginMusicDeliveryArgs(e, _provider))).ToList();

                _continuePlay = results.Count == 0 || results.All(result => !result);

                if (!_continuePlay)
                {
                    _waveOut?.Stop();
                }

                if (_continuePlay)
                {
                    _waveOut.Play();
                }

                if ((_provider.MaxBufferSize - _provider.Length) > e.Samples.Length)
                {
                    _provider.Write(e.Samples, 0, e.Samples.Length);
                    consumed = e.Frames;
                }
            }

            e.ConsumedFrames = consumed;
        }
コード例 #5
0
ファイル: TorshifySongPlayer.cs プロジェクト: jmazouri/Picofy
        public void PlaySong(ITrack song)
        {
            _waveOut?.Stop();
            Session.PlayerPause();
            Session.PlayerUnload();

            lock (_lockObject)
            {
                _provider = null;
            }

            var errorCode = Session.PlayerLoad(song);

            if (!song.WaitUntilLoaded(500) || errorCode != Error.OK)
            {
                MessageBox.Show("Error: " + errorCode);
                return;
            }

            Session.PlayerPlay();
        }