c# - 如何将波信号分成帧

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

我正在一个有关和弦识别的项目。我使用某人的日记作为引用,但在DSP Realm 我仍然知之甚少。在她的引用文献中,第一件事是我需要将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 ms。
我是否需要将FileStream拆分并分成帧并保存到数组中?还是其他?

最佳答案

使用NAudio,您可以这样做:

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

正如其他人所评论的那样,如果您打算将其传递给FFT,则读取的样本数应为2的幂。同样,如果文件是立体声文件,则将左右采样进行交错,因此您的FFT将需要能够解决这一问题。

关于c# - 如何将波信号分成帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9254224/

相关文章:

c# - 如何共享对内存映射文件的只读访问

android - com.googlecode.mp4parser无法获取mp3音频文件?

audio - 语音/音乐分类

linux - 是否可以向 TSTP 发出信号,然后在发生超时时将其杀死

audio - 如何设置动态时间扭曲窗口调整?

c# - SQL 查询比较 Datetime 时 SQLDependency 失败

c# - 在代码隐藏中更改时,TextBox 中的文本不会立即更新

c# - 实现 IComparable 接口(interface)

python - 获取声音文件中给定时间的振幅?

audio - ffmpeg 流偏移命令(-itsoffset)不起作用