This project has moved and is read-only. For the latest updates, please go here.

How to get frequency from a .wav audio file

Jun 5, 2013 at 11:01 AM
Edited Jun 5, 2013 at 11:05 AM
I want to get frequency and amplitude from wave file using c#. I tried NAudio and FFT, but result is nothing. I am newbie in the programmer, can you help me please.
  private void wavToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Wave File (*.wav)|*.wav;";
            if (open.ShowDialog() != DialogResult.OK) return;

            chart1.Series.Add("wave");
            chart1.Series["wave"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
            chart1.Series["wave"].ChartArea = "ChartArea1";

            NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName));

            byte[] buffer = new byte[8192];
            int read = 0;
            while (wave.Position < wave.Length)
            {
                read = wave.Read(buffer, 0, 8192);

                for (int i = 0; i < read / 4; i++)
                {
                    chart1.Series["wave"].Points.Add(BitConverter.ToSingle(buffer, i * 4));

                }

            }

        }
how advanced code above to get the frequency?

as the example below:

http://naudio.codeplex.com/discussions/440149

output:
bin freq     result.X                     result.Y
0    0kHz = 0.0895436406135559 0
1    2.756kHz = -0.0815449208021164 -0.072540670633316
2    5.512kHz = 0.0273693520575762 0.0248471423983574
3    8.268kHz = 0.000522108399309218 -0.00102939654607326
4   11.024kHz = -0.00428497046232224 -0.00206405459903181
5   13.78kHz = -0.0028145220130682 0.00431088916957378
6   16.536kHz = 0.00255107693374157 -0.00238887779414654
7   19.292kHz = 0.000449806451797485 1.36718153953552E-05
Jun 7, 2013 at 10:56 AM
Have a look at this article I wrote which explains how to use FFT with NAudio.

http://channel9.msdn.com/coding4fun/articles/AutotuneNET

You will need to be aware that FFT is one of the hardest concepts for a newbie to audio programming to grasp, so expect to spend a while learning about it.

Mark