当前位置: 首页>>代码示例>>C#>>正文


C# BufferedWaveProvider.ClearBuffer方法代码示例

本文整理汇总了C#中NAudio.Wave.BufferedWaveProvider.ClearBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedWaveProvider.ClearBuffer方法的具体用法?C# BufferedWaveProvider.ClearBuffer怎么用?C# BufferedWaveProvider.ClearBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NAudio.Wave.BufferedWaveProvider的用法示例。


在下文中一共展示了BufferedWaveProvider.ClearBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FfmpegListener


//.........这里部分代码省略.........
                return;
            }

            RecordingFormat = new WaveFormat(_afr.SampleRate, 16, _afr.Channels);
            _waveProvider = new BufferedWaveProvider(RecordingFormat) { DiscardOnBufferOverflow = true, BufferDuration = TimeSpan.FromMilliseconds(500) };

            _sampleChannel = new SampleChannel(_waveProvider);
            _sampleChannel.PreVolumeMeter += SampleChannelPreVolumeMeter;

            int mult = _afr.BitsPerSample / 8;
            double btrg = Convert.ToDouble(_afr.SampleRate * mult * _afr.Channels);
            LastFrame = DateTime.UtcNow;
            bool realTime = !IsFileSource;

            try
            {
                DateTime req = DateTime.UtcNow;
                while (!_stopEvent.WaitOne(10, false) && !MainForm.ShuttingDown)
                {
                    byte[] data = _afr.ReadAudioFrame();
                    if (data == null || data.Equals(0))
                    {
                        if (!realTime)
                        {
                            break;
                        }
                    }
                    if (data != null && data.Length > 0)
                    {
                        LastFrame = DateTime.UtcNow;
                        var da = DataAvailable;
                        if (da != null)
                        {
                            //forces processing of volume level without piping it out
                            _waveProvider.AddSamples(data, 0, data.Length);

                            var sampleBuffer = new float[data.Length];
                            _sampleChannel.Read(sampleBuffer, 0, data.Length);

                            da(this, new DataAvailableEventArgs((byte[])data.Clone()));

                            if (WaveOutProvider != null && Listening)
                            {
                                WaveOutProvider.AddSamples(data, 0, data.Length);
                            }

                        }

                        if (realTime)
                        {
                            if (_stopEvent.WaitOne(30, false))
                                break;
                        }
                        else
                        {
                            //
                            double f = (data.Length / btrg) * 1000;
                            if (f > 0)
                            {
                                var span = DateTime.UtcNow.Subtract(req);
                                var msec = Convert.ToInt32(f - (int)span.TotalMilliseconds);
                                if ((msec > 0) && (_stopEvent.WaitOne(msec, false)))
                                    break;
                                req = DateTime.UtcNow;
                            }
                        }
                    }
                    else
                    {
                        if ((DateTime.UtcNow - LastFrame).TotalMilliseconds > Timeout)
                        {
                            throw new Exception("Audio source timeout");
                        }
                        if (_stopEvent.WaitOne(30, false))
                            break;
                    }

                }

            }
            catch (Exception e)
            {
                MainForm.LogExceptionToFile(e, "FFMPEG");
                errmsg = e.Message;
            }

            if (_sampleChannel != null)
            {
                _sampleChannel.PreVolumeMeter -= SampleChannelPreVolumeMeter;
                _sampleChannel = null;
            }

            if (_waveProvider != null)
            {
                if (_waveProvider.BufferedBytes > 0)
                    _waveProvider.ClearBuffer();
            }

            ShutDown(errmsg);
        }
开发者ID:vavavr00m,项目名称:ispyconnect,代码行数:101,代码来源:FFMPEGStream.cs

示例2: CanClearBeforeWritingSamples

 public void CanClearBeforeWritingSamples()
 {
     var bwp = new BufferedWaveProvider(new WaveFormat(44100, 16, 2));
     bwp.ClearBuffer();
     Assert.AreEqual(0, bwp.BufferedBytes);
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:6,代码来源:BufferedWaveProviderTests.cs

示例3: FfmpegListener


//.........这里部分代码省略.........
                _afr.Timeout = Timeout;
                _afr.AnalyzeDuration = AnalyseDuration;
                _afr.Headers = Headers;
                _afr.Cookies = Cookies;
                _afr.UserAgent = UserAgent;
                _afr.Open(_source);
                open = true;
            }
            catch (Exception ex)
            {
                Logger.LogExceptionToFile(ex,"FFMPEG");
            }
            finally
            {
                try
                {
                    Program.FfmpegMutex.ReleaseMutex();
                }
                catch (ObjectDisposedException)
                {
                    //can happen on shutdown
                }
            }

            if (_afr == null || !_afr.IsOpen || !open)
            {
                ShutDown("Could not open audio stream" + ": " + _source);
                return;
            }

            RecordingFormat = new WaveFormat(_afr.SampleRate, 16, _afr.Channels);
            _waveProvider = new BufferedWaveProvider(RecordingFormat) { DiscardOnBufferOverflow = true, BufferDuration = TimeSpan.FromMilliseconds(500) };

            _sampleChannel = new SampleChannel(_waveProvider);
            _sampleChannel.PreVolumeMeter += SampleChannelPreVolumeMeter;

            LastFrame = DateTime.UtcNow;

            try
            {
                while (!_stopEvent.WaitOne(10, false) && !MainForm.ShuttingDown)
                {
                    byte[] data = _afr.ReadAudioFrame();
                    if (data!=null && data.Length > 0)
                    {
                        LastFrame = DateTime.UtcNow;
                        var da = DataAvailable;
                        if (da != null)
                        {
                            //forces processing of volume level without piping it out
                            _waveProvider.AddSamples(data, 0, data.Length);

                            var sampleBuffer = new float[data.Length];
                            int read = _sampleChannel.Read(sampleBuffer, 0, data.Length);

                            da(this, new DataAvailableEventArgs((byte[])data.Clone(),read));

                            if (Listening)
                            {
                                WaveOutProvider?.AddSamples(data, 0, read);
                            }

                        }

                        if (_stopEvent.WaitOne(30, false))
                            break;

                    }
                    else
                    {
                        if ((DateTime.UtcNow - LastFrame).TotalMilliseconds > Timeout)
                        {
                            throw new Exception("Audio source timeout");
                        }
                        if (_stopEvent.WaitOne(30, false))
                            break;
                    }

                }

            }
            catch (Exception e)
            {
                Logger.LogExceptionToFile(e,"FFMPEG");
                errmsg = e.Message;
            }

            if (_sampleChannel != null)
            {
                _sampleChannel.PreVolumeMeter -= SampleChannelPreVolumeMeter;
                _sampleChannel = null;
            }

            if (_waveProvider?.BufferedBytes > 0)
                _waveProvider.ClearBuffer();

            if (WaveOutProvider?.BufferedBytes > 0) WaveOutProvider?.ClearBuffer();

            ShutDown(errmsg);
        }
开发者ID:ispysoftware,项目名称:iSpy,代码行数:101,代码来源:FFMPEGStream.cs


注:本文中的NAudio.Wave.BufferedWaveProvider.ClearBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。