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


C# WaveFileWriter.Dispose方法代码示例

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


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

示例1: FlushUpdatesHeaderEvenIfDisposeNotCalled

 public void FlushUpdatesHeaderEvenIfDisposeNotCalled()
 {
     var ms = new MemoryStream();
     var testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
     var testSequence2 = new byte[] { 0x3, 0x4, 0x5 };
     var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(16000, 24, 1));
     writer.Write(testSequence, 0, testSequence.Length);
     writer.Flush();
     // BUT NOT DISPOSED
     // another write that was not flushed
     writer.Write(testSequence2, 0, testSequence2.Length);
     
     // check the Reader can read it
     ms.Position = 0;
     using (var reader = new WaveFileReader(ms))
     {
         Assert.AreEqual(16000, reader.WaveFormat.SampleRate, "Sample Rate");
         Assert.AreEqual(24, reader.WaveFormat.BitsPerSample, "Bits Per Sample");
         Assert.AreEqual(1, reader.WaveFormat.Channels, "Channels");
         Assert.AreEqual(testSequence.Length, reader.Length, "File Length");
         var buffer = new byte[600]; // 24 bit audio, block align is 3
         int read = reader.Read(buffer, 0, buffer.Length);
         Assert.AreEqual(testSequence.Length, read, "Data Length");
         
         for (int n = 0; n < read; n++)
         {
             Assert.AreEqual(testSequence[n], buffer[n], "Byte " + n);
         }
     }
     writer.Dispose(); // to stop the finalizer from moaning
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:31,代码来源:WaveFileWriterTests.cs

示例2: 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

示例3: RecordAudioFile

 public virtual void RecordAudioFile()
 {
     string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
     string wavFile = Path.Combine (currentDirectory, "recording.wav");
     long writtenSamples = 0;
     WaveFileWriter writer = new WaveFileWriter (wavFile, _jackIn.WaveFormat);
     _jackIn.DataAvailable += (sender, args) => {
         writer.Write (args.Buffer, 0, args.BytesRecorded);
     };
     _jackIn.RecordingStopped += (sender, e) => {
         writer.Flush ();
         writer.Dispose ();
         long fileSize = new FileInfo (wavFile).Length;
         Assert.AreNotEqual (0, fileSize);
     };
     _jackIn.StartRecording ();
     Thread.Sleep (100);
     _jackIn.StopRecording ();
     writtenSamples = writer.Length;
     Assert.AreNotEqual (0, writtenSamples);
 }
开发者ID:residuum,项目名称:JackSharp,代码行数:21,代码来源:JackInTest.cs

示例4: CreateWaveFile2

 public static void CreateWaveFile2(string filename, IWaveProvider sourceProvider)
 {
     using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
     {
         long outputLength = 0;
         var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
         while (true)
         {
             int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
             {
                 // end of source provider
                 break;
             }
             outputLength += bytesRead;
             // Write will throw exception if WAV file becomes too large
             if (bytesRead > 0)
             {
                 writer.Write(buffer, 0, bytesRead);
             }
         }
         writer.Dispose();
     }
 }
开发者ID:Qder,项目名称:MusicEditor,代码行数:24,代码来源:WavFileUtils.cs

示例5: WordToWAV


//.........这里部分代码省略.........
                        {
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency);
                            Thread.Sleep(dash);
                        }

                        if (symbol == '\'')
                        {
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency);
                            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;
                    }

                    WavPause(writer, interval * dash * dynamic_interval);  // Пауза между словами

                } // End for(i)

                writer.Close();
                writer.Dispose();

            } // end using

            // Конвертим WAV-файл в MP3-файл
            if (File.Exists(fileName + ".wav"))
                ConvertWavToMP3(fileName);
            else
            {
                if (english_flag)
                    MessageBox.Show("No exist WAV-file to conver in MP3.");
                else
                    MessageBox.Show(fileName + ".wav ", "Нет WAV-файла для конвертации в MP3.");
            }
            // Переместить звуковые файлы
            if (alternative_mp3_flag)
            {
                try
                {
                    // MessageBox.Show("Конвертим с задержкой MP3.");
                    // Не успевает LAME отрабоать - заддерка нужна
                    Thread.Sleep(5000);     // 5 секунд

                    if (File.Exists(fileName + ".mp3"))
                    {
                        // Удаляем старые файлы
                        if (File.Exists(fileNameOld + ".mp3 "))
                            File.Delete(fileNameOld + ".mp3 ");

                        //Переносим файлы из корня диска в папку, указанную пользователем
                        File.Move(fileName + ".mp3 ", fileNameOld + ".mp3");
                    }
                    else
                        MessageBox.Show(fileName + ".mp3 ", "Нет MP3-файла!");

                    if (File.Exists(fileName + ".wav"))
                    {
                        //MessageBox.Show(fileName + ".wav ", "Старый файл WAV");
                        //MessageBox.Show(fileNameOld + ".wav ", "Новый файл WAV");
                       // MessageBox.Show(fileName + ".mp3 ", "Старый файл MP3");
                       // MessageBox.Show(fileNameOld + ".mp3 ", "Новый файл MP3");

                        // Удаляем старые файлы
                        if (File.Exists(fileNameOld + ".wav "))
                            File.Delete(fileNameOld + ".wav ");

                        //Переносим файлы из корня диска в папку, указанную пользователем
                        File.Move(fileName + ".wav ", fileNameOld + ".wav");
                    }

                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "The process move a audiofiles failed!");
                }
            }
        }
开发者ID:richmanfx,项目名称:cw_win_4,代码行数:101,代码来源:Cw_winForm.cs

示例6: 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

示例7: 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


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