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


C# Mp3FileReader.Read方法代码示例

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


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

示例1: CanLoadAndReadVariousProblemMp3Files

 public void CanLoadAndReadVariousProblemMp3Files()
 {
     string testDataFolder = @"C:\Users\Mark\Downloads\NAudio";
     if (!Directory.Exists(testDataFolder))
     {
         Assert.Ignore("{0} not found", testDataFolder);
     }
     foreach (string file in Directory.GetFiles(testDataFolder, "*.mp3"))
     {
         string mp3File = Path.Combine(testDataFolder, file);
         Debug.WriteLine(String.Format("Opening {0}", mp3File));
         using (var reader = new Mp3FileReader(mp3File))
         {
             byte[] buffer = new byte[4096];
             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:ActivePHOENiX,项目名称:NAudio,代码行数:25,代码来源:Mp3FileReaderTests.cs

示例2: GetNextChunk

        public double[][] GetNextChunk(int samplesDesired, Mp3FileReader fr, bool fullnormalize = false)
        {
            byte[] buffer = new byte[samplesDesired * 4];
            short[] left = new short[samplesDesired];
            //short[] right = new short[samplesDesired];
            double[] leftd = new double[samplesDesired];
            //double[] rightd = new double[samplesDesired];

            int bytesRead = 0;

            try
            {
                bytesRead = fr.Read(buffer, 0, 4 * samplesDesired);
            }
            catch
            {
                new Exception("An error occurred while reading file");
            }

            int index = 0;
            for (int sample = 0; sample < bytesRead / 4; sample++)
            {
                left[sample] = BitConverter.ToInt16(buffer, index); index += 2;
                //right[sample] = BitConverter.ToInt16(buffer, index);
                index += 2;
            }

            if (fullnormalize)
                leftd = Utilities.NormalizeFull(ref left, left.Length);
            else
                leftd = Utilities.Normalize(ref left, left.Length);

            return new double[][] { leftd, null }; //rightd };
        }
开发者ID:johnnybuggy,项目名称:HOLO1,代码行数:34,代码来源:SoundReader.cs

示例3: mp3Processor

        public mp3Processor(string file)
        {
            buf = new byte[maxLen];

            WaveStream mp3Reader = new Mp3FileReader(file);
            int read = mp3Reader.Read(buf, 0, buf.Length);
            len = read;
        }
开发者ID:vlad7777,项目名称:Music-Recognition,代码行数:8,代码来源:mp3Processor.cs

示例4: getByteArray

 public static byte[] getByteArray(string file, ref int len, ref int channels)
 {
     byte[] buf = new byte[maxLen];
     WaveStream mp3Reader = new Mp3FileReader(file);
     channels = mp3Reader.WaveFormat.Channels;
     int read = mp3Reader.Read(buf, 0, buf.Length);
     len = read;
     return buf;
 }
开发者ID:vlad7777,项目名称:Music-Recognition,代码行数:9,代码来源:mp3Processor.cs

示例5: MakeSnaps

            public bool MakeSnaps(int _snapsize, int _snapcount, string _path, int smooth_size)
            {
                try
                {
                    using (Mp3FileReader pcm = new Mp3FileReader(_path))
                    {
                        int samplesDesired = _snapsize;
                        int blockscount = _snapcount;

                        snap_size = _snapsize;
                        snap_count = _snapcount;
                        total_samples = pcm.Length;
                        length = pcm.TotalTime.Seconds;
                        path = _path;

                        if ((pcm.WaveFormat.SampleRate != 44100) || (pcm.WaveFormat.BitsPerSample != 16))
                            return false;

                        for (int i = 0; i < blockscount; i++)
                        {
                            byte[] buffer = new byte[samplesDesired * 4];
                            short[] left = new short[samplesDesired];
                            short[] right = new short[samplesDesired];
                            double[] leftd = new double[samplesDesired];
                            double[] rightd = new double[samplesDesired];

                            int bytesRead = 0;

                            //for (int j = 0; j < 1; j++) ///////////
                            int seek_counter = 0;
                        seek: pcm.Seek((i + 1) * (i + 1) * (i + 1) * blockscount * samplesDesired % (total_samples - samplesDesired), SeekOrigin.Begin);
                            seek_counter++;

                            bytesRead = pcm.Read(buffer, 0, 4 * samplesDesired);

                            int index = 0;
                            for (int sample = 0; sample < bytesRead / 4; sample++)
                            {
                                left[sample] = BitConverter.ToInt16(buffer, index); index += 2;
                                right[sample] = BitConverter.ToInt16(buffer, index); index += 2;
                            }

                            if (left.Average(t => Math.Abs(t)) == 0)
                                if (seek_counter > 5)
                                    return false;
                                else
                                    goto seek;

                            //snap_log10_energy.Add(Math.Log10(left.Average(t => Math.Abs(t))));

                            leftd = Normalize(left, left.Length);
                            rightd = Normalize(right, right.Length);

                            //alglib.complex[] fl;
                            //alglib.fftr1d(leftd, out fl);
                            //fl[0].x;

                            FourierTransformer ft = new FourierTransformer(samplesDesired);
                            var xxa = new Complex[leftd.Length];

                            for (int j = 0; j < leftd.Length; j++)
                                xxa[j] = new Complex(leftd[j], rightd[j]);

                            var ftt = ft.Transform(xxa);

                            List<double> pow_re_im = new List<double>();
                            //List<double> arg_re_im = new List<double>();

                            ftt.ToList().ForEach(t => pow_re_im.Add(ComplexMath.Abs(t)));
                            //ftt.ToList().ForEach(t => arg_re_im.Add(ComplexMath.Arg(t)));

                            /*if (Double.IsNaN(MC_Log10_Energy(pow_re_im)))
                                if (seek_counter > 5)
                                    return false;
                                else
                                    goto seek;*/

                            fft_snaps.Add(pow_re_im);
                            //fft_smoothed_snaps.Add(Smoothen(pow_re_im, smooth_size));

                            //pow_re_im = Normalize(pow_re_im);

                            /*
                            var f_pwri = pow_re_im.Average(t => Math.Abs(t));
                            for (int k = 0; k < pow_re_im.Count; k++)
                                pow_re_im[k] = (Math.Abs(pow_re_im[k]) >= f_pwri * 1.5) ? pow_re_im[k] : 0;
                            */

                            /*
                            FourierTransformer ft2 = new FourierTransformer(samplesDesired);
                            var xx2 = new List<Complex>();
                            for (int j = 0; j < pow_re_im.Count; j++)
                            {
                                xx2.Add(new Complex(pow_re_im[j], arg_re_im[j]));
                            }
                            var ftt2 = ft2.Transform(xx2);
                            //var ftt2 = ft2.Transform(ftt);

                            List<double> pow_re_im2 = new List<double>();
                            ftt2.ToList().ForEach(t => pow_re_im2.Add(ComplexMath.Abs(t)));
//.........这里部分代码省略.........
开发者ID:develop1,项目名称:holo,代码行数:101,代码来源:Form1.cs

示例6: PlayAudioFile

        private static byte[] PlayAudioFile(string substring)
        {
            //return File.ReadAllBytes(substring);
            Console.WriteLine("Playing...");
            Stream inputStream = new MemoryStream(File.ReadAllBytes(substring));
            inputStream.Seek(0, SeekOrigin.Begin);
            Stream outputStream = new MemoryStream();
            byte[] bytes = new byte[inputStream.Length];
            string path = @"C:\temp";
            string wavFile = @"C:\temp\tempWav.wav";

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            if (File.Exists(wavFile))
                File.Delete(wavFile);

            using (var reader = new Mp3FileReader(substring))
            {
                using (var writer = new WaveFileWriter(wavFile, new WaveFormat()))
                {
                    var buf = new byte[4096];
                    for (; ; )
                    {
                        var cnt = reader.Read(buf, 0, buf.Length);
                        if (cnt == 0) break;
                        writer.Write(buf, 0, cnt);
                    }
                }
            }

            //SoundPlayer p = new SoundPlayer(wavFile);
            //p.Play();
            return File.ReadAllBytes(wavFile);
        }
开发者ID:DrewJordan,项目名称:Streaming-Audio-Server,代码行数:35,代码来源:Program.cs

示例7: ConvertMp3ToWav

 /// <summary>
 /// Convert a MP3 file to a Wav file
 /// </summary>
 /// <param name="mp3FilePath"></param>
 /// <param name="wavFilePath"></param>
 public static void ConvertMp3ToWav(string mp3FilePath, string wavFilePath)
 {
     using (var reader = new Mp3FileReader(mp3FilePath)) {
         using (var writer = new WaveFileWriter(wavFilePath, new WaveFormat())) {
             byte[] buffer = new byte[16*1024];
             for (;;) {
                 int bytes = reader.Read(buffer, 0, buffer.Length);
                 if (bytes == 0) break;
                 writer.Write(buffer, 0, bytes);
             }
         }
     }
 }
开发者ID:remy22,项目名称:AudioVSTToolbox,代码行数:18,代码来源:AudioUtilsNAudio.cs


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