如何使用NAudio对波形文件执行FFT [英] How to perform the FFT to a wave-file using NAudio

查看:523
本文介绍了如何使用NAudio对波形文件执行FFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NAudio库,希望对WaveStream执行快速傅立叶变换.我看到NAudio已经内置了FFT,但是我该如何使用它呢?

I'm working with the NAudio-library and would like to perform the fast fourier transformation to a WaveStream. I saw that NAudio has already built-in the FFT but how do I use it?

听说我必须使用SampleAggregator类.

I heard i have to use the SampleAggregator class.

推荐答案

您需要阅读整个博客文章,以最好地理解我提出的以下代码示例,以确保即使没有文章,该示例也得以保留:

You need to read this entire blog article to best understand the following code sample I lifted to ensure the sample is preserved even if the article isn't:

using (WaveFileReader reader = new WaveFileReader(fileToProcess))
{
    IWaveProvider stream32 = new Wave16toFloatProvider(reader);
    IWaveProvider streamEffect = new AutoTuneWaveProvider(stream32, autotuneSettings);
    IWaveProvider stream16 = new WaveFloatTo16Provider(streamEffect);
    using (WaveFileWriter converted = new WaveFileWriter(tempFile, stream16.WaveFormat))
    {
        // buffer length needs to be a power of 2 for FFT to work nicely
        // however, make the buffer too long and pitches aren't detected fast enough
        // successful buffer sizes: 8192, 4096, 2048, 1024
        // (some pitch detection algorithms need at least 2048)
        byte[] buffer = new byte[8192]; 
        int bytesRead;
        do
        {
            bytesRead = stream16.Read(buffer, 0, buffer.Length);
            converted.WriteData(buffer, 0, bytesRead);
        } while (bytesRead != 0 && converted.Length < reader.Length);
    }
}

但是简而言之,如果您创建了WAV文件,则可以使用该示例将其转换为FFT.

but in short, if you get the WAV file created you can use that sample to convert it to FFT.

这篇关于如何使用NAudio对波形文件执行FFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆