如何从.wav声音转换为double [] C# [英] How to get from .wav sound into double[] C#
问题描述
我需要执行FFT,并且我有一个声音样本.wav格式.
函数需要double[] xRe, double[] xIm, REAL PART and imaginary part
如何将声音文件转换为double []?
我从未见过这样的事情.在互联网上找不到这种操作.
这是声音示例:
http://www.speedyshare.com/fFD8t/e.wav
I need to perform FFT and I have a sound sample .wav format.
The function needs double[] xRe, double[] xIm, REAL PART and imaginary part
How to convert the sound file into double[]?
I have never seen something like that. Could not find in the internet that kind of operation.
This is this sound sample:
http://www.speedyshare.com/fFD8t/e.wav
请帮助,因为我使用过Pascal,但现在不知道该怎么办.
Please help, cause I used Pascal and now don't know what to do here.
推荐答案
这是一个简单的流操作.
It's a simple stream operation.
- 您必须阅读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文件格式的信息:
And here you can read about WAV file format:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
关于WAV的复数和FFT:
And something about WAV as complex numbers and FFT:
这篇关于如何从.wav声音转换为double [] C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!