gpt4 book ai didi

c# - 音频,FFT不起作用

转载 作者:行者123 更新时间:2023-12-03 00:46:26 27 4
gpt4 key购买 nike

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]);
}
}

}

}

使用AForge的FFT时遇到此问题。这是正确的使用方式吗?返回的复数(此时仅返回前500个)每次都将第二个数字设为0。

最佳答案

您正在打印错误的数据:

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

关于c# - 音频,FFT不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26247821/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com