c# - 如何从 .wav 声音进入双 [] C#

标签 c# audio

我需要执行 FFT,并且我有一个声音样本 .wav 格式。 该函数需要double[] xRe, double[] xIm, REAL PART和虚部 如何将声音文件转换成double[]? 我从来没有见过这样的事情。在互联网上找不到那种操作。 这是这个声音样本: http://www.speedyshare.com/fFD8t/e.wav

请帮忙,因为我用的是 Pascal,现在不知道该做什么。

最佳答案

这是一个简单的流操作。

  1. 你必须阅读 wav 文件头。
  2. 你必须读取数据字节。

从 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:

How to convert wave data into Complex numbers

关于c# - 如何从 .wav 声音进入双 [] C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390472/

相关文章:

c# - 如何连接需要SSH的远程Mysql服务器?

c# - 为什么在 c# 中通过启动进程运行 powershell 时不导入 powershell 模块?

c# - 使用 Automapper 将某些属性从 TSource 映射到 TDestination,而不会丢失旧的其他 TDestination 对象属性值

c# - 通用接口(interface)具体类型之间没有隐式引用转换错误

C# 转换错误 (DataRow)

sprite-kit - Sprite Kit中无尽的声音

audio - 无法使用媒体源扩展名.API 播放 .aac 扩展名音频文件

IOS:将 XMP 元数据添加到 AAC 编码的 m4a 文件的好方法?

javax.sound.sampled 它是如何工作的?

c# - 使用NAudio在Unity中创建AudioClip,在读取数据时卡住1-2秒