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


C# Wave.WaveFileReader类代码示例

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


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

示例1: AudioPlayer

        public AudioPlayer(Resource resource, TabPage tab)
        {
            var soundData = (Sound)resource.Blocks[BlockType.DATA];

            var stream = soundData.GetSoundStream();
            waveOut = new WaveOutEvent();

            if (soundData.Type == Sound.AudioFileType.WAV)
            {
                var rawSource = new WaveFileReader(stream);
                waveOut.Init(rawSource);
            }
            else if (soundData.Type == Sound.AudioFileType.MP3)
            {
                var rawSource = new Mp3FileReader(stream);
                waveOut.Init(rawSource);
            }

            playButton = new Button();
            playButton.Text = "Play";
            playButton.TabIndex = 1;
            playButton.Size = new Size(100, 25);
            playButton.Click += PlayButton_Click;

            tab.Controls.Add(playButton);
        }
开发者ID:SteamDatabase,项目名称:ValveResourceFormat,代码行数:26,代码来源:AudioPlayer.cs

示例2: PlayMusic

        public void PlayMusic(string sample, IAudioClient voiceClient)
        {
            using (WaveFileReader pcm = new WaveFileReader(sample))
            {
                int blocksize = pcm.WaveFormat.AverageBytesPerSecond / 5;
                byte[] buffer = new byte[blocksize];
                int offset = 0;

                    try
                    {
                        while (offset < pcm.Length / blocksize && !skip)
                        {
                            if (currentPlaying != sample)
                            {

                            }

                            offset++;
                            pcm.Read(buffer, 0, blocksize);

                            voiceClient.Send(buffer, 0, blocksize);
                            //voiceClient.Wait();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Write(e.ToString());
                    }
            }
            return;
        }
开发者ID:epicmiro,项目名称:DiscoBot,代码行数:31,代码来源:MusicQueue.cs

示例3: ConcatenateWav

        /// <summary>
        /// Merge multiple .wav files together and save the output.
        /// </summary>
        /// <param name="outputFile">The path to save the output to.</param>
        /// <param name="sourceFiles">An IEnumerable list of files to merge.</param>
        private static void ConcatenateWav(string outputFile, IEnumerable<string> sourceFiles) {
            byte[] buffer = new byte[1024];
            WaveFileWriter waveFileWriter = null;
            
            try {
                foreach (string sourceFile in sourceFiles) {
                    using (WaveFileReader reader = new WaveFileReader(sourceFile)) {
                        if (waveFileWriter == null) {
                            // first time in create new Writer
                            waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
                        }
                        else {
                            if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat)) {
                                throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
                            }
                        }

                        int read;
                        while ((read = reader.Read(buffer, 0, buffer.Length)) > 0) {
                            waveFileWriter.WriteData(buffer, 0, read);
                        }
                    }
                }
            }
            finally {
                if (waveFileWriter != null) {
                    waveFileWriter.Dispose();
                }
            }

        }
开发者ID:bearhack145,项目名称:fluid-vocal,代码行数:36,代码来源:WavMod.cs

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

示例5: ReaderShouldReadBackSameDataWrittenWithWrite

 public void ReaderShouldReadBackSameDataWrittenWithWrite()
 {
     var ms = new MemoryStream();
     var testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
     using (var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(16000, 24, 1)))
     {
         writer.Write(testSequence, 0, testSequence.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);
         }
     }
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:25,代码来源:WaveFileWriterTests.cs

示例6: OutputWaveToFile

        public void OutputWaveToFile(
            string textToSpeak,
            string waveFile)
        {
            if (string.IsNullOrWhiteSpace(textToSpeak))
            {
                return;
            }

            this.StartSasara();

            var tempWave = Path.GetTempFileName();

            talker.OutputWaveToFile(
                textToSpeak,
                tempWave);

            // ささらは音量が小さめなので増幅する
            using (var reader = new WaveFileReader(tempWave))
            {
                var prov = new VolumeWaveProvider16(reader);
                prov.Volume = Settings.Default.SasaraGain;

                WaveFileWriter.CreateWaveFile(
                    waveFile,
                    prov);
            }

            if (File.Exists(tempWave))
            {
                File.Delete(tempWave);
            }
        }
开发者ID:kinokonoyama,项目名称:ACT.TTSYukkuri,代码行数:33,代码来源:SasaraController.cs

示例7: AudioSample

        public AudioSample(string fileName)
        {
            _fileName = fileName;
            WaveFileReader reader = new WaveFileReader(fileName);
            //offsetStream = new WaveOffsetStream(reader);
            //channelStream = new WaveChannel32(offsetStream);
            channelStream = new WaveChannel32(reader);
            muted = false;
            volume = 1.0f;



            #region ReverseStuff

            //Code to reverse
            NAudioBufferReverse nbr = new NAudioBufferReverse();
            reversedSample = new byte[(int)channelStream.Length];
            channelStream.Read(reversedSample, 0, (int)channelStream.Length);
            bytesPerSample = (channelStream.WaveFormat.BitsPerSample / 8) * channelStream.WaveFormat.Channels;
            reversedSample = nbr.reverseSample(reversedSample, (int)channelStream.Length, bytesPerSample);

            #endregion


        }
开发者ID:LuckyLuik,项目名称:_GLDNBT,代码行数:25,代码来源:NAudioSample.cs

示例8: WavToMP3

        /// <summary>
        ///  Convert WAV to MP3 using libmp3lame library
        /// </summary>
        /// <param name="waveFileName">WAV filename</param>
        /// <param name="mp3FileName">MP3 filename</param>
        /// <param name="bitRate">Bit rate, default 128</param>
        /// <param name="artist">Optional artist name</param>
        /// <param name="album">Optional album name</param>
        /// <param name="setID3Tags">Set ID3 tags</param>
        public static bool WavToMP3(string waveFileName, string mp3FileName, int bitRate = 128, string artist = null, string album = null, bool setID3Tags = false, string genre = "148")
        {
            bool result = true;
            try
            {
                ID3TagData tags = new ID3TagData();
                if (setID3Tags)
                {
                    if (!String.IsNullOrEmpty(artist))
                    {
                        tags.Artist = artist;
                        tags.Album = album;
                        tags.Genre = genre;
                    }
                }

                using (var reader = new WaveFileReader(waveFileName))
                using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate, tags))
                    reader.CopyTo(writer);

            }
            catch (Exception)
            {
                result = false;
            }

            return result;
        }
开发者ID:simondgh,项目名称:WavToMP3,代码行数:37,代码来源:Form1.cs

示例9: PianoSynth

        public PianoSynth()
        {
            mixer = new WaveMixerStream32();
            mixer.AutoStop = false;

            int i = 0;
            foreach (var note in noteFiles)
            {
                reader[i] = new WaveFileReader(note);

                offsetStream[i] = new WaveOffsetStream(reader[i]);
                channelSteam[i] = new WaveChannel32(offsetStream[i]);
                channelSteam[i].Position = channelSteam[i].Length;
                mixer.AddInputStream(channelSteam[i]);

                i++;
            }

            if (waveOutDevice == null)
            {
                waveOutDevice = new WaveOut {DeviceNumber = 0};
                waveOutDevice.Init(mixer);
                waveOutDevice.Volume = 0;
                waveOutDevice.Play();
                waveOutDevice.Volume = 100;
            }
        }
开发者ID:grazulis,项目名称:KinectRainbowSynth,代码行数:27,代码来源:PianoSynth.cs

示例10: CanLoadAndReadVariousProblemWavFiles

 public void CanLoadAndReadVariousProblemWavFiles()
 {
     string testDataFolder = @"C:\Users\Mark\Downloads\NAudio";
     if (!Directory.Exists(testDataFolder))
     {
         Assert.Ignore("{0} not found", testDataFolder);
     }
     foreach (string file in Directory.GetFiles(testDataFolder, "*.wav"))
     {
         string wavFile = Path.Combine(testDataFolder, file);
         Debug.WriteLine(String.Format("Opening {0}", wavFile));
         using (var reader = new WaveFileReader(wavFile))
         {
             byte[] buffer = new byte[reader.WaveFormat.AverageBytesPerSecond];
             int bytesRead;
             int total = 0;
             do
             {
                 bytesRead = reader.Read(buffer, 0, buffer.Length);
                 total += bytesRead;
             } while (bytesRead > 0);
             Debug.WriteLine(String.Format("Read {0} bytes", total));
         }
     }
 }
开发者ID:jithuin,项目名称:infogeezer,代码行数:25,代码来源:WaveFileReaderTests.cs

示例11: playbackFile

 public void playbackFile(string filename)
 {
     WaveFileReader reader = new WaveFileReader(filename);
     WaveChannel32 channelStream = new WaveChannel32(reader);
     mixer.AddInputStream(channelStream);
     channelStream.Position = 0;
 }
开发者ID:hyupeng,项目名称:CSharp-Piano-Test,代码行数:7,代码来源:AudioPlayer.cs

示例12: Read

        public static Sound Read(Stream source)
        {
            BinaryReaderEx reader = new BinaryReaderEx(source);
            Sound result = new Sound();

            int id = reader.ReadInt32();
            if (id == 0x00394453)
            {
                int headerLength = reader.ReadInt32();
                int sampleLength = reader.ReadInt32();

                headerLength -= 12;
                if (headerLength > 0)
                    reader.ReadBytes(headerLength);

                byte[] wavData = reader.ReadBytes(sampleLength);
                using (MemoryStream wavDataMem = new MemoryStream(wavData))
                {
                    using (WaveStream wavStream = new WaveFileReader(wavDataMem))
                    {
                        byte[] rawWaveData = new byte[wavStream.Length];
                        wavStream.Read(rawWaveData, 0, (int)wavStream.Length);
                        result.SetSound(rawWaveData, wavStream.WaveFormat);
                    }
                }
            }

            return result;
        }
开发者ID:NoOnes2,项目名称:scharfrichter,代码行数:29,代码来源:BemaniSD9.cs

示例13: BonIverStemPlayer

        // set everything up
        public BonIverStemPlayer(Engine.Engine engine) {
            mixer.AutoStop = false;
            waveOutDevice.Init(mixer);
            Engine = engine;

            // load in each of our files
            reader[0] = new WaveFileReader(@"C:\\Users\\Badger\\repos\\balloon\\SkeletalTracking\\boniver\\bangorkook.wav");
            reader[1] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\chippewa_falls.wav");
            reader[2] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\eleva.wav");
            reader[3] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\gilman.wav");
            reader[4] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\grand_rapids.wav");
            reader[5] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\heigh_on.wav");
            reader[6] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\lake_hallie.wav");
            reader[7] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\le_grange_wi.wav");
            reader[8] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\long_plain.wav");
            reader[9] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\mandolin_wa.wav");
            reader[10] = new WaveFileReader(@"C:\Users\Badger\repos\balloon\SkeletalTracking\boniver\virginia.wav");

            // set the starting positions
            // and load into the mixer
            for (int i = 0; i < 11; i++) {
                channelStream[i] = new WaveChannel32(reader[i]);
                channelStream[i].Position = 0;
                mixer.AddInputStream(channelStream[i]);
            }
        }
开发者ID:probuilderz,项目名称:balloon,代码行数:27,代码来源:BonIverStemPlayer.cs

示例14: EncodeFile

 private void EncodeFile()
 {
     string inputFileName = GetInputFileName("Select PCM WAV File to Encode");
     if (inputFileName == null)
         return;
     using (var reader = new WaveFileReader(inputFileName))
     {
         if (reader.WaveFormat.Encoding != WaveFormatEncoding.Pcm)
         {
             MessageBox.Show("Please select a PCM WAV file to encode");
             return;
         }
         WaveFormat targetFormat = GetTargetFormat(reader.WaveFormat);
         if (targetFormat == null)
         {
             return;
         }
         string outputFileName = GetOutputFileName("Select Ouput File Name");
         if (outputFileName == null)
         {
             return;
         }
         using (WaveStream convertedStream = new WaveFormatConversionStream(targetFormat, reader))
         {
             WaveFileWriter.CreateWaveFile(outputFileName, convertedStream);
         }
         if (checkBoxAutoLaunchConvertedFile.Checked)
         {
             System.Diagnostics.Process.Start(outputFileName);
         }
     }
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:32,代码来源:AcmPanel.cs

示例15: SoundResource

        public SoundResource(ResourceManager mgr, string fullName, Stream stream, Format fmt)
        {
            _manager = mgr;
            FullName = fullName;

            switch (fmt)
            {
                case Format.MP3:
                {
                    Mp3FileReader mp3 = new Mp3FileReader(stream);
                    _reader = mp3;
                    break;
                }
                case Format.WAV:
                {
                    WaveFileReader wav = new WaveFileReader(stream);
                    _reader = wav;
                    break;
                }
                default:
                    throw new InvalidOperationException("Unsupported extension.");
            }

            _stream = new WaveChannel32(_reader);
            _stream.PadWithZeroes = false;

            _wavDevice.PlaybackStopped += _wavDevice_PlaybackStopped;
        }
开发者ID:Veggie13,项目名称:Genesis,代码行数:28,代码来源:SoundResource.cs


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