简体   繁体   中英

audio, FFT not working

class Main
{

    WaveFileReader reader;
    short[] sample;
    Complex[] tmpComplexArray;

    public Main()
    {

        //read in wav, to raw data in byte array then to short array.
        reader = new WaveFileReader("C:\\Users\\minford\\Downloads\\English_Subtitles_.wav");

        byte[] buffer = new byte[reader.Length];
        reader.Read(buffer, 0 , buffer.Length);
        sample = new short[reader.Length];
        for (int n = 0; n < buffer.Length; n += 2)
        {
            sample[n] = BitConverter.ToInt16(buffer, n);

        }




        // short array to complex
       Complex[] complexData = new Complex[sample.Length];
        for (int i = 0; i < complexData.Length; i++)
        {
            Complex tmp = new Complex(sample[i],0);

            complexData[i] = tmp;


        }

        //to get first 500 for testing.
        tmpComplexArray = new Complex[500];
        for (int i = 0; i < 500; i++)
        {
           Complex a = new Complex(complexData[i]);
           tmpComplexArray[i] = a;
        }
        //run FFT
        FourierTransform.DFT(tmpComplexArray ,FourierTransform.Direction.Forward);

        //print result
        for (int i = 0; i < complexData.Length; i++)
        {
            Console.Write(complexData[i]);
        }
    }

}

}

I have this problem while using the FFT from AForge. Is this the correct way of using it? the complex numbers that get returned(only returning the first 500 at the moment) have the second number as 0 every time.

You are printing out the wrong data:

    //print result      vvvvvvvvvvvvvvv
    for (int i = 0; i < tmpComplexArray.Length; i++)
    {
        Console.Write(tmpComplexArray[i]);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM