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


C# WaveFileReader.ReadNextSampleFrame方法代碼示例

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


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

示例1: CanAccessSamplesIndividuallyInAMonoFile

 public void CanAccessSamplesIndividuallyInAMonoFile()
 {
     var ms =  new MemoryStream();
     using (var writer = new WaveFileWriter( new IgnoreDisposeStream(ms), new WaveFormat(8000, 16, 1)))
     {
         writer.WriteSample(0.1f);
         writer.WriteSample(0.2f);
         writer.WriteSample(0.3f);
         writer.WriteSample(0.4f);
     }
     ms.Position = 0;
     using (var reader = new WaveFileReader(ms))
     {
         Assert.AreEqual(0.1f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.AreEqual(0.2f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.AreEqual(0.3f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.AreEqual(0.4f, reader.ReadNextSampleFrame()[0], 0.001f);
         Assert.IsNull(reader.ReadNextSampleFrame());
     }
 }
開發者ID:ActivePHOENiX,項目名稱:NAudio,代碼行數:20,代碼來源:WaveFileReaderTests.cs

示例2: CanAccessSamplesIndividuallyInAStereo24BitFile

        public void CanAccessSamplesIndividuallyInAStereo24BitFile()
        {
            var ms = new MemoryStream();
            using (var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(44100, 24, 2)))
            {
                writer.WriteSample(0.1f);
                writer.WriteSample(0.2f);
                writer.WriteSample(0.3f);
                writer.WriteSample(0.4f);

            }
            ms.Position = 0;
            using (var reader = new WaveFileReader(ms))
            {
                var f1 = reader.ReadNextSampleFrame();
                Assert.AreEqual(0.1f, f1[0], 0.0001f);
                Assert.AreEqual(0.2f, f1[1], 0.0001f);
                var f2 = reader.ReadNextSampleFrame();
                Assert.AreEqual(0.3f, f2[0], 0.0001f);
                Assert.AreEqual(0.4f, f2[1], 0.0001f);
                Assert.IsNull(reader.ReadNextSampleFrame());
            }
        }
開發者ID:EraYaN,項目名稱:Moonstone,代碼行數:23,代碼來源:WaveFileReaderTests.cs

示例3: GetVolumesDiscrete

        public static int[] GetVolumesDiscrete(byte[] wav, double intervalSec)
        {
            using (var ms = new MemoryStream(wav))
            using (var fr = new WaveFileReader(ms))
            {
                var totalTime = fr.TotalTime;

                int[] result = new int[(int)(totalTime.TotalSeconds / intervalSec)];
                for (int i = 0; i < result.Length; i++)
                {
                    var normalizedVolumes = new List<float>();
                    var nextIntervalStart = TimeSpan.FromSeconds((i + 1) * intervalSec);
                    if(nextIntervalStart > totalTime)
                    {
                        nextIntervalStart = totalTime;
                    }

                    while (fr.CurrentTime < nextIntervalStart)
                    {
                        float[] volumes = fr.ReadNextSampleFrame();
                        foreach (var volume in volumes)
                        {
                            normalizedVolumes.Add(volume);
                        }
                    }

                    //見ての通り二乗値を平均して平方根を取る
                    double v = Math.Sqrt(normalizedVolumes
                        .Select(n => n * n)
                        .Sum() / normalizedVolumes.Count
                        );

                    result[i] = v < Thresh0 ? 0 :
                                v < Thresh1 ? 1 :
                                v < Thresh2 ? 2 :
                                v < Thresh3 ? 3 :
                                v < Thresh4 ? 4 : 5;

                }

                return result;
            }
        }
開發者ID:malaybaku,項目名稱:harriet,代碼行數:43,代碼來源:WaveInfoWithNAudio.cs

示例4: GetMax

        /// <summary>
        /// Gets the maximum.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>
        /// Max float value in file
        /// </returns>
        private static float GetMax(string file)
        {
            using (var reader = new WaveFileReader(file))
            {
                float[] buffer;
                float max = 0;

                while ((buffer = reader.ReadNextSampleFrame()) != null)
                {
                    for (var n = 0; n < buffer.Length; n++)
                    {
                        max = Math.Max(max, Math.Abs(buffer[n]));
                    }
                }

                return max;
            }
        }
開發者ID:ptorchilov,項目名稱:mp3-editor,代碼行數:25,代碼來源:EffectsUtility.cs.cs

示例5: Play2

 public Play2(string file)
 {
     WaveFileReader reader = new WaveFileReader(file);
     frame = (int)reader.Length / 2;
     sampleBufferL = new double[frame];
     sampleBufferR = new double[frame];
     float[] buffer;
     while ((buffer = reader.ReadNextSampleFrame()) != null)
     {
         for (int i = 0; i*2 < buffer.Length; i++)
         {
             sampleBufferL[n] = buffer[i*2];
             sampleBufferR[n] = buffer[i*2+1];
         }
         n++;
     }
     WaveFormat format = reader.WaveFormat;
     ch = format.Channels;
     n = 0;
     speed = 1;
 }
開發者ID:ryo-okabayashi,項目名稱:sound,代碼行數:21,代碼來源:Gen.cs

示例6: Play

 public Play(string file)
 {
     WaveFileReader reader = new WaveFileReader(file);
     sampleBuffer = new double[reader.Length];
     float[] buffer;
     while ((buffer = reader.ReadNextSampleFrame()) != null)
     {
         for (int i = 0; i < buffer.Length; i++)
         {
             sampleBuffer[n++] = buffer[i];
         }
     }
     WaveFormat format = reader.WaveFormat;
     ch = format.Channels;
     frame = sampleBuffer.Length / ch;
     n = 0;
     speed = 1;
 }
開發者ID:ryo-okabayashi,項目名稱:sound,代碼行數:18,代碼來源:Gen.cs

示例7: LoadSamplesWav

        private IEnumerable<float[]> LoadSamplesWav(string aPath)
        {
            using (var reader = new WaveFileReader(aPath))
            {
                var frames = new List<float[]>();

                while (true)
                {
                    var frame = reader.ReadNextSampleFrame();

                    if (frame == null)
                    {
                        return frames;
                    }

                    frames.Add(frame);
                }
            }
        }
開發者ID:cropotkin,項目名稱:glass,代碼行數:19,代碼來源:Program.cs

示例8: ChangeVolume

        /// <summary>指定したパーセンテージで音量を増減させた新しいwavデータを生成します。</summary>
        /// <param name="wav">元のwavデータ</param>
        /// <param name="factorPercent">音量のパーセンテージ(0~200くらいを想定)</param>
        /// <returns>音量を変更したあとのwavデータ</returns>
        public static byte[] ChangeVolume(byte[] wav, int factorPercent)
        {
            var result = new byte[wav.Length];

            using (var msIn = new MemoryStream(wav))
            using (var fr = new WaveFileReader(msIn))
            using (var msOut = new MemoryStream(result))
            using (var fw = new WaveFileWriter(msOut, fr.WaveFormat))
            {
                var allVolumes = new List<float>();
                while (fr.CurrentTime < fr.TotalTime)
                {
                    var vs = fr.ReadNextSampleFrame();
                    foreach (var v in vs)
                    {
                        allVolumes.Add(v);
                    }
                }

                fw.WriteSamples(
                    allVolumes.Select(v => v * factorPercent / 100.0f).ToArray(),
                    0, 
                    allVolumes.Count
                    );
            }

            return result;
        }
開發者ID:malaybaku,項目名稱:harriet,代碼行數:32,代碼來源:WaveInfoWithNAudio.cs

示例9: getWavWaveForm

        private List<float> getWavWaveForm(WaveFileReader reader)
        {
            List<float> data = new List<float>();
            float[] buffer;

            while ((buffer = reader.ReadNextSampleFrame()) != null)
            {
                data.Add(buffer[0]);
            }
            return data;
        }
開發者ID:jrocket,項目名稱:MOG,代碼行數:11,代碼來源:WaveformService.cs

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


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