开发者

Reading Audio Data from MP3 using Naudio

开发者 https://www.devze.com 2023-01-31 03:48 出处:网络
I want to split the audio data of a mp3 file and perform an FFT transformation on each of the chunks.

I want to split the audio data of a mp3 file and perform an FFT transformation on each of the chunks.

All of my attempts to read from the audio stream did not work so far. Here is the code for my last attempt (it uses a wav file)

        using (var ms = File.OpenRead("reggae.wav"))
       开发者_如何学运维  using (var rdr = new WaveFileReader(ms)) 
         {
             int steps = 100;
             int stepSize = (int)rdr.Length / steps;

             byte[][] audData = new byte[steps][];


             for (int i = 0; i < 10; i++)
             {
                 audData[i] = new byte[stepSize];
                 rdr.Read(audData[i], i * steps, stepSize);
             }

         }

I get an array out of bounds exception with this code.

What kind of streams do I have to use and how do I read the data from it?

Is there any documentation for the naudio api?


the array out of bounds exception is caused by you passing in a non-zero value for offset to the Read method. It should be:

rdr.Read(audData[i], 0, stepSize);

There are several articles on the web explaining how to do different things in NAudio

  • NAudio articles on my blog
  • Skype Voice Changer article at Coding4Fun
  • .NET Voice Recorder article at Coding4Fun

For examples of using FFT with NAudio, look at the WpfDemo app in the NAudio source code, and also at the .NET voice recorder application source code (hopefully another article on Coding4Fun will appear shortly).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号