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


C# WaveOut.Dispose方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            var adj = new AdjustableTFunc {Value = 1600};

            var tFuncWaveProvider = new TFuncWaveProvider
                {
            //                  Amplitude = TFunc.Sin(new Frequency(adj.TFunc))
            //                  Amplitude = TFunc.Sin(new Frequency(t => TFuncs.Sin(Frequency.Hertz(1))(t) + 1000))
                    Amplitude = TFunc.Sin(TFunc.Sin(Frequency.Hertz(2)) + 1000)
                };
            var waveOut = new WaveOut();
            waveOut.Init(tFuncWaveProvider);
            waveOut.Play();

            Console.WriteLine("Press q to kill");
            char k;
            while ((k = Console.ReadKey().KeyChar) != 'q')
            {
                if (k == 'u')
                {
                    adj.Value+=10;
                }
                if (k == 'd')
                {
                    adj.Value-=10;
                }
                Console.Write(" ");
                Console.WriteLine(adj.Value);
            }

            waveOut.Stop();
            waveOut.Dispose();
        }
开发者ID:rmichela,项目名称:Acoustico,代码行数:33,代码来源:Program.cs

示例2: PlaySound

 public void PlaySound(string name, Action done = null)
 {
     FileStream ms = File.OpenRead(_soundLibrary[name]);
     var rdr = new Mp3FileReader(ms);
     WaveStream wavStream = WaveFormatConversionStream.CreatePcmStream(rdr);
     var baStream = new BlockAlignReductionStream(wavStream);
     var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
     waveOut.Init(baStream);
     waveOut.Play();
     var bw = new BackgroundWorker();
     bw.DoWork += (s, o) =>
                      {
                          while (waveOut.PlaybackState == PlaybackState.Playing)
                          {
                              Thread.Sleep(100);
                          }
                          waveOut.Dispose();
                          baStream.Dispose();
                          wavStream.Dispose();
                          rdr.Dispose();
                          ms.Dispose();
                          if (done != null) done();
                      };
     bw.RunWorkerAsync();
 }
开发者ID:guozanhua,项目名称:KinectGestures,代码行数:25,代码来源:MainWindow.xaml.cs

示例3: Main

        static void Main(string[] args)
        {
            // for recording
            waveFileWriter = new WaveFileWriter(@"C:\rec\out.wav", new WaveFormat(44100, 2));

            var sound = new MySound();
            sound.SetWaveFormat(44100, 2);
            sound.init();
            waveOut = new WaveOut();
            waveOut.Init(sound);
            waveOut.Play();

            ConsoleKeyInfo keyInfo;
            bool loop = true;
            while (loop)
            {
                keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Q)
                {
                    waveOut.Stop();
                    waveOut.Dispose();
                    waveFileWriter.Close();
                    waveFileWriter.Dispose();
                    loop = false;
                }
            }
        }
开发者ID:ryo-okabayashi,项目名称:sound,代码行数:27,代码来源:Program.cs

示例4: Execute

        public void Execute()
        {
            if(this.StreamStarted != null)
                this.StreamStarted(this, EventArgs.Empty);

            MediaFoundationReader reader = new MediaFoundationReader(this.Video.DownloadUrl);
            WaveOut player = new WaveOut(); 
            player.Init(reader);
            player.Play();
            
            while(player.PlaybackState != PlaybackState.Stopped)
            {
                if (this.StreamPositionChanged != null)
                    this.StreamPositionChanged(this, new ProgressEventArgs(reader.CurrentTime.Seconds * reader.TotalTime.Seconds / 100));
                Thread.Sleep(1000);
            }

            if(this.StreamFinished != null)
                this.StreamFinished(this, EventArgs.Empty);

            player.Dispose();
        }
开发者ID:kelvinRosa,项目名称:YoutubeExtractor,代码行数:22,代码来源:AudioStreamer.cs

示例5: Main

        static void Main(string[] args)
        {
            var waveOut = new WaveOut();
            var encoder = new Source();
            waveOut.Init(encoder);
            waveOut.Play();

            Stopwatch timer = new Stopwatch();
            timer.Start();
            while (timer.Elapsed < new TimeSpan(0, 0, 5))
            {
                encoder.SetTimecode(new LTCSharp.Timecode(
                    timer.Elapsed.Hours,
                    timer.Elapsed.Minutes,
                    timer.Elapsed.Seconds,
                    (int) ((float)timer.Elapsed.Milliseconds / 1000.0f * 30.0f)));
                Thread.Sleep(10);
            }
            timer.Stop();

            waveOut.Stop();
            waveOut.Dispose();
        }
开发者ID:sebllll,项目名称:LTCSharp,代码行数:23,代码来源:Program.cs

示例6: Stream

    public void Stream(string url, bool async) {
      if (url == null) { return; }

      WaveOut WaveOutPlay = new WaveOut(WaveCallbackInfo.FunctionCallback());
      WaveOutPlay.DeviceNumber = device;

      using (var ms = new MemoryStream())
      using (var stream = WebRequest.Create(url).GetResponse().GetResponseStream()) {
        byte[] buffer = new byte[32768]; int read;
        while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
          ms.Write(buffer, 0, read);
        }
        ms.Position = 0;

        // Play WaveStream
        bool wav = url.ToLower().EndsWith(".wav") || url.ToLower().EndsWith(".wma");
        var reader = wav ? WaveFormatConversionStream.CreatePcmStream(new WaveFileReader(ms))
                         : (WaveStream)new Mp3FileReader(ms);

        RunSession(WaveOutPlay, reader, url);
      }

      WaveOutPlay.Dispose();
    }
开发者ID:jdelhommeau,项目名称:WSRMacro,代码行数:24,代码来源:WSRSpeaker.cs

示例7: Play

    public void Play(string fileName, bool async) {
      if (fileName == null) { return; }
      if (fileName.StartsWith("http")) {
        Stream(fileName, async);
        return;
      }
      if (!File.Exists(fileName)) { return; }

      // Play WaveStream
      bool wav = fileName.ToLower().EndsWith(".wav") || fileName.ToLower().EndsWith(".wma");
      var reader = wav ? WaveFormatConversionStream.CreatePcmStream(new WaveFileReader(fileName))
                       : (WaveStream)new Mp3FileReader(fileName);

      WaveOut WaveOutPlay = new WaveOut(WaveCallbackInfo.FunctionCallback());
      WaveOutPlay.DeviceNumber = device;
      RunSession(WaveOutPlay, reader, fileName);
      WaveOutPlay.Dispose();
    }
开发者ID:jdelhommeau,项目名称:WSRMacro,代码行数:18,代码来源:WSRSpeaker.cs

示例8: OnMp3RepositionTestClick

 private void OnMp3RepositionTestClick(object sender, EventArgs e)
 {
     var filename = SelectInputFile();
     if (filename == null) return;
     var wo = new WaveOut();
     var af = new AudioFileReader(filename);
     wo.Init(af);
     var f = new Form();
     var b = new Button() { Text = "Play" };
     b.Click += (s, a) => wo.Play();
     var b2 = new Button() { Text = "Stop", Left = b.Right };
     b2.Click += (s, a) => wo.Stop();
     var b3 = new Button { Text = "Rewind", Left = b2.Right };
     b3.Click += (s, a) => af.Position = 0;
     f.FormClosed += (s, a) => { wo.Dispose(); af.Dispose(); };
     f.Controls.Add(b);
     f.Controls.Add(b2);
     f.Controls.Add(b3);
     f.ShowDialog(this);
 }
开发者ID:LibertyLocked,项目名称:NAudio,代码行数:20,代码来源:SimplePlaybackPanel.cs

示例9: SoundWord


//.........这里部分代码省略.........
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == ';')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == ':')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '!' && russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '!' && !russianpunktuation_flag)
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '-')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

                     if (symbol == '\'')
                     {
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dash); MyWaveOut.Stop(); Thread.Sleep(dot);
                         MyWaveOut.Play(); Thread.Sleep(dot); MyWaveOut.Stop();
                         Thread.Sleep(dash);
                     }

             } // End For j

             if (non_random_flag)
             {
                 screen_Out(word);              // вывод на label непрерывно
             }
             else
             {
                 screen_Out_By_10(i, word);     // вывод на label по 10 слов
             }

             int dynamic_interval = 1;          // Длительность динамического интервала между словами
             if (dynamic_interval_flag)
             {
                 dynamic_interval = word.Length;
             }

             Thread.Sleep(interval * dash * dynamic_interval);     // Пауза между словами

            } // End for(i)

            // Звершить работу со звуковой картой
            MyWaveOut.Dispose();
            MyWaveOut = null;
        }
开发者ID:richmanfx,项目名称:cw_win_4,代码行数:101,代码来源:Cw_winForm.cs

示例10: Play

		public void Play(object sender, MouseButtonEventArgs e)
		{
			var button = (NumboardButton)sender;
			if (button == null) return;
			if (button.Source == null) return;

			if (!File.Exists(button.Source))
			{
				MessageBox.Show("Cannot Find file '" + button.Source + "'");
				return;
			}

			var fileType = System.IO.Path.GetExtension(button.Source);

			var volume = button.Volume;
			if (volume == null)
			{
				volume = 1;
			}

			//primary ouput
			var primaryReader = new AudioFileReader(button.Source);
			primaryReader.Volume = (float)(volume * MasterVolume);
			
			var primaryWaveOut = new WaveOut();
			primaryWaveOut.DeviceNumber = SelectedPrimaryOutputDevice;

			//secondary ouput
			var secondaryReader = new AudioFileReader(button.Source);
			secondaryReader.Volume = (float)(volume * MasterVolume);

			var secondaryWaveOut = new WaveOut();
			secondaryWaveOut.DeviceNumber = SelectedSecondaryOutputDevice;

			primaryWaveOut.PlaybackStopped += StopStream;

			try
			{

				primaryWaveOut.Init(primaryReader);
				primaryWaveOut.Play();

				secondaryWaveOut.Init(secondaryReader);
				secondaryWaveOut.Play();

				PlayingStreams.Add(new PlayingStream { Button = button, PrimaryReader = primaryReader, SecondaryReader = secondaryReader, PrimaryWaveOut = primaryWaveOut, SecondaryWaveOut = secondaryWaveOut });

			}
			catch (MmException ex)
			{
				primaryReader.Dispose();
				primaryWaveOut.Dispose();
				secondaryReader.Dispose();
				secondaryWaveOut.Dispose();

				if (ex.Result == MmResult.MemoryAllocationError)
				{
					StopAllStreams();
				}
			}
		}
开发者ID:Shadetheartist,项目名称:Numboard-2.0,代码行数:61,代码来源:AudioManager.cs

示例11: _Beep

 private static void _Beep(int frequency, int duration)
 {
     WaveOut wo = new WaveOut();
     SquareWaveProvider wp = new SquareWaveProvider();
     if (frequency != 0)
     {
         wp.Frequency = frequency;
         wo.Init(wp);
         wo.Play();
     }
     Thread.Sleep(duration);
     if (frequency != 0)
         wo.Stop();
     wo.Dispose();
 }
开发者ID:DCNick3,项目名称:MidToCArray,代码行数:15,代码来源:MusicTwo.cs

示例12: PlayInThread

        private void PlayInThread(object data)
        {
            string filename = (string)data;

            _waveOutDevice = new WaveOut();
            WaveChannel32 inputStream = null;
            WaveStream mp3Reader = null;

            try
            {
                if (SupportedFileTypes.CanBePlayed(filename))
                {
                    mp3Reader = new Mp3FileReader(filename);

                    inputStream = new WaveChannel32(mp3Reader);
                }
                else
                {
                    throw new InvalidOperationException("Unsupported extension");
                }

                _waveOutDevice.Init(inputStream);
                _waveOutDevice.Volume = _volume;
                _waveOutDevice.PlaybackStopped += _waveOutDevice_PlaybackStopped;
                _waveOutDevice.Play();

                Log.Debug("Playing " + filename);

                Thread.Sleep(mp3Reader.TotalTime);
            }
            catch (Exception exc)
            {
                Log.Debug("Error while playing song " + filename + ":" + exc.ToString());
            }
            finally
            {
                _waveOutDevice.Stop();
                if (mp3Reader!=null)
                    mp3Reader.Close();

                if (inputStream!=null)
                    inputStream.Close();

                _waveOutDevice.Dispose();
            }
        }
开发者ID:awlawl,项目名称:Maestro,代码行数:46,代码来源:NAudioInteractor.cs


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