我需要执行 FFT,并且我有一个声音样本 .wav 格式。
该函数需要double[] xRe, double[] xIm, REAL PART和虚部
如何将声音文件转换成double[]?
我从来没有见过这样的事情。在互联网上找不到那种操作。
这是这个声音样本:
http://www.speedyshare.com/fFD8t/e.wav
请帮忙,因为我用的是 Pascal,现在不知道该做什么。
最佳答案
这是一个简单的流操作。
- 你必须阅读 wav 文件头。
- 你必须读取数据字节。
从 MSDN 粘贴:
BinaryReader reader = new BinaryReader(waveFileStream);
//Read the wave file header from the buffer.
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32();
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int channels = reader.ReadInt16();
int sampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int bitDepth = reader.ReadInt16();
if (fmtSize == 18)
{
// Read any extra values
int fmtExtraSize = reader.ReadInt16();
reader.ReadBytes(fmtExtraSize);
}
int dataID = reader.ReadInt32();
int dataSize = reader.ReadInt32();
// Store the audio data of the wave file to a byte array.
byteArray = reader.ReadBytes(dataSize);
// After this you have to split that byte array for each channel (Left,Right)
// Wav supports many channels, so you have to read channel from header
这里有更详细的解释:
http://msdn.microsoft.com/en-us/library/ff827591.aspx
在这里您可以阅读有关 WAV 文件格式的信息:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
关于作为复数的 WAV 和 FFT:
关于c# - 如何从 .wav 声音进入双 [] C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390472/