Click here to Skip to main content
15,902,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to be able to display a waveform from a .wav in a graph using a Complex structure so that it can have a Fourier Transform (FFT) done on it and then display that in a secondary graph. I don't want to use NAudio and keep libraries at a minimum, how do I fix my code so that I can display the waveform?

What I have tried:

C#
<pre>
Complex[] InputWave = new Complex[1000];
        int sampleRate;
        int fileSize;

private void LoadWave()
        {
            try
            {
                using (FileStream FS = File.Open(fileAddressBox.Text, FileMode.Open))
                {
                    BinaryReader BReader = new BinaryReader(FS);

                    int chunkID = BReader.ReadInt32();
                    fileSize = BReader.ReadInt32();
                    int riffType = BReader.ReadInt32();
                    int sbchunk1ID = BReader.ReadInt32();
                    int sbchunk1Size = BReader.ReadInt32();
                    int AudioFormat = BReader.ReadInt16();
                    int channels = BReader.ReadInt16();
                    sampleRate = BReader.ReadInt32();
                    int byteRate = BReader.ReadInt32();
                    int blockAlign = BReader.ReadInt16();
                    int bitDepth = BReader.ReadInt16();
                    

                    InputWave = new Complex[fileSize];
                    byte[] byteArray = new byte[fileSize];

                    for (int i = 0; i < fileSize; i++)
                    {
                        byteArray[i] = BReader.ReadByte();
                        InputWave[i] = BitConverter.ToInt32(byteArray,i);
                        double time = ((i + 1.0) / fileSize) / 2;
                        fileChart.Series["Input Wave"].Points.AddXY(time, InputWave[i].Real);
                    }

                }
            }
            catch
            {

            }
        }
Posted
Updated 6-Feb-20 8:34am

1 solution

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900