當前位置: 首頁>>代碼示例>>C#>>正文


C# WaveFileWriter.WriteData方法代碼示例

本文整理匯總了C#中NAudio.Wave.WaveFileWriter.WriteData方法的典型用法代碼示例。如果您正苦於以下問題:C# WaveFileWriter.WriteData方法的具體用法?C# WaveFileWriter.WriteData怎麽用?C# WaveFileWriter.WriteData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NAudio.Wave.WaveFileWriter的用法示例。


在下文中一共展示了WaveFileWriter.WriteData方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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);
             }
         }
     }
 }
開發者ID:bearhack145,項目名稱:fluid-vocal,代碼行數:14,代碼來源:WavFileUtils.cs

示例2: CreateWaveFile

 /// <summary>
 /// Creates a Wave file by reading all the data from a WaveStream
 /// </summary>
 /// <param name="filename">The filename to use</param>
 /// <param name="stream">The source WaveStream</param>
 public static void CreateWaveFile(string filename, WaveStream stream)
 {
     using (WaveFileWriter writer = new WaveFileWriter(filename, stream.WaveFormat))
     {
         byte[] buffer = new byte[stream.GetReadSize(4000)];
         while (true)
         {
             int bytesRead = stream.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
                 break;
             writer.WriteData(buffer, 0, bytesRead);
         }
     }
 }
開發者ID:Punloeu,項目名稱:karaoke,代碼行數:19,代碼來源:WaveFileWriter.cs

示例3: ApplyAutoTune

 public static void ApplyAutoTune(string fileToProcess, string tempFile, AutoTuneSettings autotuneSettings)
 {
     using (WaveFileReader reader = new WaveFileReader(fileToProcess))
     {
         IWaveProvider stream32 = new Wave16toIeeeProvider(reader);
         IWaveProvider streamEffect = new AutoTuneWaveProvider(stream32, autotuneSettings);
         IWaveProvider stream16 = new WaveIeeeTo16Provider(streamEffect);
         using (WaveFileWriter converted = new WaveFileWriter(tempFile, stream16.WaveFormat))
         {
             // buffer length needs to be a power of 2 for FFT to work nicely
             // however, make the buffer too long and pitches aren't detected fast enough
             // successful buffer sizes: 8192, 4096, 2048, 1024
             // (some pitch detection algorithms need at least 2048)
             byte[] buffer = new byte[8192]; 
             int bytesRead;
             do
             {
                 bytesRead = stream16.Read(buffer, 0, buffer.Length);
                 converted.WriteData(buffer, 0, bytesRead);
             } while (bytesRead != 0 && converted.Length < reader.Length);
         }
     }
 }
開發者ID:cristian25cd,項目名稱:PMC,代碼行數:23,代碼來源:AutoTuneUtils.cs

示例4: ConvertSample

        XSample ConvertSample(int count, SSampleHeader sh, byte [] sample, Zone izone)
        {
            // Indices in sf2 are numbers of samples, not byte length. So double them.
            var xs = new XSample ();
            xs.Extension = ".wav";
            xs.LoopStart =(sh.StartLoop - sh.Start);
            xs.LoopEnd = (sh.EndLoop - sh.Start);
            int sampleModes = izone.SampleModes ();
            xs.LoopMode = sampleModes == 0 ? InstrumentSampleLoopMode.Off : InstrumentSampleLoopMode.Forward;
            xs.Name = String.Format ("Sample{0:D02} ({1})", count, sh.SampleName);
            xs.BaseNote = (sbyte) izone.OverridingRootKey ();
            //			xs.Volume = (izone.VelocityRange () & 0xFF00 >> 8); // low range
            if (xs.BaseNote == 0)
                xs.BaseNote = (sbyte) sh.OriginalPitch;
            //Console.WriteLine ("{0} ({1}/{2}/{3}/{4}) {5}:{6}:{7}:{8}", xs.Name, sh.Start, sh.StartLoop, sh.EndLoop, sh.End, sh.SampleRate != 0xAC44 ? sh.SampleRate.ToString () : "", sh.OriginalPitch != 60 ? sh.OriginalPitch.ToString () : "", sh.PitchCorrection != 0 ? sh.PitchCorrection.ToString () : "", sampleModes);
            xs.FileName = xs.Name + ".wav";
            var ms = new MemoryStream ();
            var wfw = new WaveFileWriter (ms, new WaveFormat ((int) sh.SampleRate, 16, 1));
            wfw.WriteData (sample, 2 * (int) sh.Start, 2 * (int) (sh.End - sh.Start));
            wfw.Close ();
            xs.Buffer = ms.ToArray ();

            return xs;
        }
開發者ID:zeromus,項目名稱:sf2xrni,代碼行數:24,代碼來源:sf2xrni.cs

示例5: ExportWAVBtnClick

 void ExportWAVBtnClick(object sender, EventArgs e)
 {
     if(saveFileDialog1.ShowDialog() == DialogResult.OK) {
         byte[] buf = MakeByteBuf();
         WaveFileWriter wfw = new WaveFileWriter(saveFileDialog1.FileName, new WaveFormat(samplingRate, 8, 1));
         wfw.WriteData(buf, 0, buf.Length);
         wfw.Close();
     }
 }
開發者ID:akx,項目名稱:fxfxfx,代碼行數:9,代碼來源:MainForm.cs

示例6: processWave

        /// <summary>    
        /// Load wave file and change its tempo, pitch and rate and save it to another file    
        /// </summary>    
        static void processWave(string fileIn, string fileOut, float newTempo, float newPitch, float newRate)
        {
            WaveFileReader reader = new WaveFileReader(fileIn);
            int numChannels = reader.WaveFormat.Channels;
            if (numChannels > 2)
                throw new Exception("SoundTouch supports only mono or stereo.");
            int sampleRate = reader.WaveFormat.SampleRate;
            int bitPerSample = reader.WaveFormat.BitsPerSample;
            const int BUFFER_SIZE = 1024 * 16;
            SoundStretcher stretcher = new SoundStretcher(sampleRate, numChannels);
            WaveFileWriter writer = new WaveFileWriter(fileOut, new WaveFormat(sampleRate, 16, numChannels));
            stretcher.Tempo = newTempo;
            stretcher.Pitch = newPitch;
            stretcher.Rate = newRate;
            byte[] buffer = new byte[BUFFER_SIZE];
            short[] buffer2 = null;

            if (bitPerSample != 16 && bitPerSample != 8)
            {
                throw new Exception("Not implemented yet.");
            }

            if (bitPerSample == 8)
            {
                buffer2 = new short[BUFFER_SIZE];
            }

            bool finished = false;
            while (true)
            {
                int bytesRead = 0;
                if (!finished)
                {
                    bytesRead = reader.Read(buffer, 0, BUFFER_SIZE);
                    if (bytesRead == 0)
                    {
                        finished = true;
                        stretcher.Flush();
                    }
                    else
                    {
                        if (bitPerSample == 16)
                        {
                            stretcher.PutSamplesFromBuffer(buffer, 0, bytesRead);
                        }
                        else if (bitPerSample == 8)
                        {
                            for (int i = 0; i < BUFFER_SIZE; i++)
                                buffer2[i] = (short)((buffer[i] - 128) * 256);
                            stretcher.PutSamples(buffer2);
                        }
                    }
                }

                bytesRead = stretcher.ReceiveSamplesToBuffer(buffer, 0, BUFFER_SIZE);
                writer.WriteData(buffer, 0, bytesRead);
                if (finished && bytesRead == 0)
                    break;
            }

            reader.Close();
            writer.Close();
        }
開發者ID:jakelly,項目名稱:SermonProcessor,代碼行數:66,代碼來源:Program.cs


注:本文中的NAudio.Wave.WaveFileWriter.WriteData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。