当前位置: 首页>>代码示例>>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;未经允许,请勿转载。