【问题标题】:how to split wave signal into frames如何将波信号分成帧
【发布时间】:2012-03-04 11:35:50
【问题描述】:

我正在做一个关于和弦识别的项目。我正在使用某人的期刊作为参考,但我对 DSP 领域的了解仍然很少。在她的参考资料中,第一件事是我需要将 wav 文件中的信号拆分为帧数。就我而言,我需要将每帧分割成 65 毫秒,每帧有 2866 个样本。

我已经搜索了如何将信号拆分为帧,但我发现它们不够清晰,我无法理解。 到目前为止,这些是我在 WavProcessing 类中的一些代码:

 public void SetFileName(String fileNameWithPath) //called first in the form, to get the FileStream
    {
        _fileNameWithPath = fileNameWithPath;
        strm = File.OpenRead(_fileNameWithPath);

    }
 public double getLengthTime(uint wavSize, uint sampleRate, int bitRate, int channels)  
    {
        wavTimeLength = ((strm.Length - 44) / (sampleRate * (bitRate / 8))) / channels;
        return wavTimeLength;
    }

public int getNumberOfFrames() //return number of frames, I just divided total length time with interval time between frames. (in my case, 3000ms / 65 ms = 46 frames)
    { 
        numOfFrames = (int) (wavTimeLength * 1000 / _sampleFrameTime);
        return numOfFrames; 
    }

 public int getSamplePerFrame(UInt32 sampleRate, int sampleFrameTime) // return the sample per frame value (in my case, it's 2866)
    {
        _sampleRate = sampleRate;
        _sampleFrameTime = sampleFrameTime;

        sFr = (int)(sampleRate * (sampleFrameTime / 1000.0 ));

        return sFr; 
    }

我仍然不明白如何在 C# 中将信号拆分为每帧 65 毫秒。 我是否需要拆分 FileStream 并将它们分成帧并将它们保存到数组中?还是别的什么?

【问题讨论】:

  • 通常你将信号拆分到大小以 2 为底的桶中。所以 128,256,512,1024 ... 因为大多数 FFT 算法都需要这个。我从来没有处理过和弦识别,但我很确定你需要某种 FFT 或 DCT 来识别音高。您将找到的大多数代码(并且有很多代码)将是裸 C。使用不成熟的代码区域使您能够复制粘贴它们。您可以在 www.musicdsp.org 找到很多内容。作为电子书,我推荐dspguide.com。太棒了!
  • 感谢您提供的信息。我会仔细看看的。实际上,我会在和弦识别部分使用增强音高类配置文件。你说我以 2 为基数分割信号,有代码示例吗?谢谢..
  • 有大量的代码示例!!但是你必须明白你在做什么!!我不知道 EPCP,只是听说过。您关于 65 毫秒的信息来自哪里?
  • 更完整的 FFT 库不再要求长度是 2 的幂,其他小因素也可以。此外,您有时可以对一帧数据进行零填充,直至达到更合适的 FFT 长度,具体取决于您需要对 FFT 结果执行什么操作。

标签: c# audio signal-processing sound-recognition music-notation


【解决方案1】:

使用 NAudio,您可以这样做:

using (var reader = new AudioFileReader("myfile.wav"))
{
    float[] sampleBuffer = new float[2866];
    int samplesRead = reader.Read(sampleBuffer, 0, sampleBuffer.Length);
}

正如其他人评论的那样,如果您打算将其传递到 FFT,则您读取的样本数应该是 2 的幂。此外,如果文件是立体声文件,您将交错左右样本,因此您的 FFT 需要能够处理这个问题。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2021-04-22
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多