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


C# WaveFileReader.Dispose方法代码示例

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


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

示例1: ConvertWavToMp3

 public static void ConvertWavToMp3(string WavFile, string outPutFile)
 {
     CheckAddBinPath();
     WaveFileReader rdr = new WaveFileReader(WavFile);
     using (var wtr = new LameMP3FileWriter(outPutFile, rdr.WaveFormat, 128))
     {
         rdr.CopyTo(wtr);
         rdr.Dispose();
         wtr.Dispose();
         return;
     }
 }
开发者ID:Qder,项目名称:MusicEditor,代码行数:12,代码来源:WavFileUtils.cs

示例2: EncodeButton_Click


//.........这里部分代码省略.........
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(503 + Int32.Parse(TextSpeed.Text));
                            break;

                       case '1':

                            str = Properties.Resources.n1;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(463 + Int32.Parse(TextSpeed.Text));
                            break;

                       case '2':

                            str = Properties.Resources.n2;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(418 + Int32.Parse(TextSpeed.Text));
                            break;

                       case '3':

                            str = Properties.Resources.n3;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(450 + Int32.Parse(TextSpeed.Text));
                            break;

                       case '4':

                            str = Properties.Resources.n4;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(507 + Int32.Parse(TextSpeed.Text));
                            break;
                       case '5':

                            str = Properties.Resources.n5;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(582 + Int32.Parse(TextSpeed.Text));
                            break;
                       case '6':

                            str = Properties.Resources.n6;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(582 + Int32.Parse(TextSpeed.Text));
                            break;
                       case '7':

                            str = Properties.Resources.n7;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(520 + Int32.Parse(TextSpeed.Text));
                            break;
                       case '8':

                            str = Properties.Resources.n8;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(373 + Int32.Parse(TextSpeed.Text));
                            break;
                       case '9':

                            str = Properties.Resources.n9;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(523 + Int32.Parse(TextSpeed.Text));
                            break;
                       case '.':
                            str = Properties.Resources.dot;
                            sp = new SoundPlayer(str);
                            sp.Play();
                            Thread.Sleep(663 + Int32.Parse(TextSpeed.Text));
                            break;

                       case ' ':
                            Thread.Sleep(Math.Abs(Int32.Parse(TextSpeed.Text)));
                            break;

                   }

                }

            }
            try
            { glc.Stop();
            glc.Dispose();
            }
            catch{}
            la.Stop();
            la.Dispose();

            wfo.Dispose();
            wc.Dispose();
            wfr.Dispose();
            GC.Collect();
        }
开发者ID:stdark,项目名称:ABC-Encoder,代码行数:101,代码来源:Form1.cs

示例3: Encode


//.........这里部分代码省略.........
				OggInterop.ogg_stream_packetin(os,header); // automatically placed in its own page
				OggInterop.ogg_stream_packetin(os,header_comments);
				OggInterop.ogg_stream_packetin(os,header_codebook);

				// This ensures the actual audio data will start on a new page, as per spec
				while(OggInterop.ogg_stream_flush(os,og) != 0)
				{
					WriteOg(og,stdout);
				}
		  
				float[][] samplebuffer = new float[reader.WaveFormat.Channels][];
				for(int channel = 0; channel < reader.WaveFormat.Channels; channel++)
				{
					samplebuffer[channel] = new float[READ];
				}

				bool eos=false;
				while(!eos)
				{
					int samples = reader.Read(samplebuffer,READ);
					if(samples == 0)
					{
						// end of file.  this can be done implicitly in the mainline,
						//but it's easier to see here in non-clever fashion.
						//Tell the library we're at end of stream so that it can handle
						//the last frame and mark end of stream in the output properly 
						OggInterop.vorbis_analysis_wrote(vd,0);
					}
					else
					{
						// data to encode 
						// expose the buffer to submit data 
						IntPtr bufferpointer = OggInterop.vorbis_analysis_buffer(vd,samples);
						int[] floatpointers = new int[reader.WaveFormat.Channels];
						Marshal.Copy(bufferpointer,floatpointers,0,reader.WaveFormat.Channels);
						for(int channel = 0; channel < reader.WaveFormat.Channels; channel++)
						{
							IntPtr channelbuffer = new IntPtr(floatpointers[channel]);
							Marshal.Copy(samplebuffer[channel],0,channelbuffer,samples);					
						}

						// tell the library how much we actually submitted
						OggInterop.vorbis_analysis_wrote(vd,samples);
					}

					// vorbis does some data preanalysis, then divvies up blocks for
					// more involved (potentially parallel) processing.  Get a single
					// block for encoding now
					while(OggInterop.vorbis_analysis_blockout(vd,vb)==1)
					{

						/* analysis, assume we want to use bitrate management */
						OggInterop.vorbis_analysis(vb,IntPtr.Zero);
						OggInterop.vorbis_bitrate_addblock(vb);

						while(OggInterop.vorbis_bitrate_flushpacket(vd,op) != 0)
						{

							/* weld the packet into the bitstream */
							OggInterop.ogg_stream_packetin(os,op);

							/* write out pages (if any) */
							while(!eos)
							{
								int result=OggInterop.ogg_stream_pageout(os,og);
								if(result==0)
									break;
								WriteOg(og,stdout);

								/* this could be set above, but for illustrative purposes, I do
								it here (to show that vorbis does know where the stream ends) */

								if(OggInterop.ogg_page_eos(og) != 0)
									eos=true;
							}
						}
					}
				}

				// clean up and exit.  vorbis_info_clear() must be called last */

				if(OggInterop.ogg_stream_clear(os) != 0)
					throw new ApplicationException("ogg_stream_clear error");
				if(OggInterop.vorbis_block_clear(vb) != 0)
					throw new ApplicationException("vorbis_block_clear error");
				OggInterop.vorbis_dsp_clear(vd);
				//vorbis_comment_clear(vc);			
				OggInterop.vorbis_info_clear(vi);
				
				
				// ogg_page and ogg_packet structs always point to storage in
				// libvorbis.  They're never freed or manipulated directly
			}
			finally
			{
				reader.Dispose();
				stdout.Close();
			}
			GC.KeepAlive(this);
		}
开发者ID:Punloeu,项目名称:karaoke,代码行数:101,代码来源:OggEncoder.cs

示例4: waveIn_RecordingStopped

        private void waveIn_RecordingStopped(object sender, EventArgs e)
        {
            if (writeToFile == 1)
            {
                waveIn.Dispose();
                waveIn = null;
                writer.Close();
                writer = null;

                int bytes_to_read = (rec_times + 1) * 6400;
                byte[] wav_bytes = new byte[bytes_to_read];

                WaveFileReader wfr = new WaveFileReader("file.wav");

                if (wfr.Length < bytes_to_read)
                {
                    wfr.Read(wav_bytes, 0, (int)wfr.Length);
                }
                else
                {
                    wfr.Position = wfr.Length - 1 - bytes_to_read;
                    wfr.Read(wav_bytes, 0, bytes_to_read);

                }
                wfr.Dispose();
                wfr.Close();

                WaveIn second_waveIn = new WaveIn();
                second_waveIn.DeviceNumber = 0;
                second_waveIn.WaveFormat = new WaveFormat(16000, 2);
                WaveFileWriter second_writer = new WaveFileWriter("cmd.wav", second_waveIn.WaveFormat);
                second_waveIn.StartRecording();
                second_writer.Write(wav_bytes, 0, bytes_to_read);
                second_waveIn.StopRecording();

                second_waveIn.Dispose();
                second_waveIn = null;
                second_writer.Close();
                second_writer = null;

                listBox1.Items.Add("CONVERTING");
                listBox1.SelectedIndex = listBox1.Items.Count - 1;

                Wav2Flac("cmd.wav", "file.flac");

                result = GoogleSpeechRequest(16000);
                string res = result;
                int k = res.IndexOf("utterance\":\"") + "utterance\":\"".Length;
                int k1 = res.IndexOf("\"", k + 1);
                string cmd = res.Substring(k, k1 - k);
                listBox1.Items.Add("RECOGNIZED");
                richTextBox1.Text += cmd + "\n";

                File.Delete("cmd.wav");
                rec_times = 0;
                writeToFile = 0;
            }
            else

                if (writeToFile == 0)
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
        }
开发者ID:Alyasko,项目名称:ComputerSpeechControl,代码行数:67,代码来源:Form1.cs

示例5: HighPassFilter

        public static void HighPassFilter(string innPath, string outtPath)
        {
            string inPath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\NowEdited.WAV";
            string outPath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\NowEdited3.WAV";

            Mp3ToWav(innPath, inPath);
            WaveFileReader reader = new WaveFileReader(inPath);
            var myFilter = BiQuadFilter.HighPassFilter(44F, 10F, 0.5F);
            WaveFileWriter writer = new WaveFileWriter(outPath, reader.WaveFormat);

            reader.Position = 0;
            var endPos = reader.Length;
            while (reader.Position < endPos)
            {
                int bytesRequired = (int)(endPos - reader.Position);
                if (bytesRequired > 0)
                {
                    float[] sample = new float[4];
                    for (int i = 0; i < 2; i++)
                    {
                        sample[i] = myFilter.Transform(reader.ReadNextSampleFrame()[i]);
                    }
                    writer.WriteSamples(sample, 0, 4);
                }
            }
            reader.Dispose();
            writer.Dispose();
            ConvertWavToMp3(outPath, outtPath);
            File.Delete(inPath);
            File.Delete(outPath);
        }
开发者ID:Qder,项目名称:MusicEditor,代码行数:31,代码来源:WavFileUtils.cs

示例6: TrimWavFile

 private static void TrimWavFile(WaveFileReader reader, WaveFileWriter writer, int startPos, int endPos)
 {
     reader.Position = startPos;
     byte[] buffer = new byte[1024];
     while (reader.Position < endPos)
     {
         int bytesRequired = (int)(endPos - reader.Position);
         if (bytesRequired > 0)
         {
             int bytesToRead = Math.Min(bytesRequired, buffer.Length);
             int bytesRead = reader.Read(buffer, 0, bytesToRead);
             if (bytesRead > 0)
             {
                 writer.WriteData(buffer, 0, bytesRead);
             }
         }
     }
     reader.Dispose();
     writer.Dispose();
 }
开发者ID:Qder,项目名称:MusicEditor,代码行数:20,代码来源:WavFileUtils.cs

示例7: wAVsCWAVsToolStripMenuItem_Click

 private void wAVsCWAVsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!File.Exists("CTR_WaveConverter32.exe"))
     {
         MessageBox.Show(messages[11],"Please understand",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     try
     {
         OpenFileDialog opn = new OpenFileDialog();
         opn.Filter = "WAV file|*.wav|Every file|*.*";
         opn.Title = "Select a WAV file";
         opn.Multiselect = true;
         if (opn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             if (opn.FileNames.Length == 1)
             {
                 Wav2CWAV(opn.FileName);
             }
             else
             {
                 for (int i = 0; i < opn.FileNames.Length; i++)
                 {
                     if (!APP_not_Optimize_Cwavs)
                     {
                         Debug.Print("Optimizing CWAV: " + Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav");
                         WaveFormat New = new WaveFormat(APP_opt_samples, 8, 1);
                         WaveStream Original = new WaveFileReader(opn.FileNames[i]);
                         WaveFormatConversionStream stream = new WaveFormatConversionStream(New, Original);
                         if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav");
                         WaveFileWriter.CreateWaveFile(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav", stream);
                         stream.Dispose();
                         Original.Dispose();
                     }
                     Process prc = new Process();
                     prc.StartInfo.FileName = "CTR_WaveConverter32.exe";
                     if (!APP_not_Optimize_Cwavs) prc.StartInfo.Arguments = "-o \"" + opn.FileNames[i] + ".bcwav\" \"" + Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav\""; else prc.StartInfo.Arguments = "-o \"" + opn.FileNames[i] + ".bcwav\" \"" + opn.FileNames[i] + "\"";
                     Debug.Print("Converting CWAV: " + Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav");
                     prc.Start();
                     prc.WaitForExit();
                     if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(opn.FileNames[i]) + ".tmp.wav");
                 }
                 MessageBox.Show("Done !");
             }
         }
     }
     catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); }
 }
开发者ID:Dark101,项目名称:YATA-PLUS,代码行数:48,代码来源:Form1.cs

示例8: Wav2CWAV

 void Wav2CWAV(string input)
 {
     SaveFileDialog sv = new SaveFileDialog();
     sv.Filter = "CWAVs|*.bcwav|Every file|*.*";
     sv.Title = "Save the CWAV file";
     if (sv.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         if (!APP_not_Optimize_Cwavs)
         {
             Debug.Print("Optimizing CWAV: " + Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav");
             WaveFormat New = new WaveFormat(APP_opt_samples, 8, 1);
             WaveStream Original = new WaveFileReader(input);
             WaveFormatConversionStream stream = new WaveFormatConversionStream(New, Original);
             if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav");
             WaveFileWriter.CreateWaveFile(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav", stream);
             stream.Dispose();
             Original.Dispose();
         }
         Process prc = new Process();
         prc.StartInfo.FileName = "CTR_WaveConverter32.exe";
         if (!APP_not_Optimize_Cwavs) prc.StartInfo.Arguments = "-o \"" + sv.FileName + "\" \"" + Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav\""; else prc.StartInfo.Arguments = "-o \"" + sv.FileName + "\" \"" +input+ "\"";
         prc.Start();
         prc.WaitForExit();
         if (System.IO.File.Exists(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav")) File.Delete(Path.GetTempPath() + Path.GetFileName(input) + ".tmp.wav");
         if (File.Exists(sv.FileName)) MessageBox.Show("Done !"); else MessageBox.Show("Error while converting the file, run the command in the cmd to check the output");
     }
 }
开发者ID:Dark101,项目名称:YATA-PLUS,代码行数:27,代码来源:Form1.cs

示例9: StopRecording

        public void StopRecording()
        {
            lock (_recordingAccessLock)
            {
                Log.Info("Finished Recording");
                MicrophoneStream.StopRecording();
                _waveWriter.Dispose();
                _waveWriter = null;
                var read = new WaveFileReader(_recordedFile);

                var d = new Description(_recordedFile, 0, read.TotalTime.TotalMilliseconds,
                    _descriptionStartTime, _recordExtended);
                OnDescriptionRecorded(d);

                read.Dispose();

                IsRecording = false;
            }
        }
开发者ID:vserrago,项目名称:LiveDescribe-Desktop,代码行数:19,代码来源:DescriptionRecorder.cs


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