2012-02-13 110 views
0

我正在开展一个关于和弦识别的项目。我使用某人的期刊作为参考,但我仍然对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并将它们拆分为帧并将它们保存到数组中?还是其他什么?

+0

通常情况下,您将信号拆分为基数为2的大小的桶。因此128,256,512,1024 ...因为大多数FFT算法都需要这个。我从来没有处理过和弦识别,但我很肯定你需要某种FFT或DCT来识别音高。你会发现大多数代码(并且那里有很多)将是裸体C.使用不规则的代码区域使你能够复制粘贴它们。你会在www.musicdsp.org找到很多。作为一本电子书,我建议http://dspguide.com/。这个棒极了! – guitarflow 2012-02-13 00:57:53

+0

这可能也是有用的http://stackoverflow.com/questions/4033083/guitar-chord-recognition-algorithm – guitarflow 2012-02-13 01:00:44

+0

谢谢你的信息。我会仔细看看的。 我实际上会使用Enhanced Pitch Class Profile作为和弦识别的一部分..你说我在2的基础上分割信号,有没有代码示例? thx .. – 2012-02-13 01:09:30

回答

0

与n音讯,你会做这样的:

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

正如其他人评论说,你看样品的数量应该是2的幂,如果您计划将它传递到FFT。另外,如果文件是立体声的,你将有左右采样交错,所以你的FFT需要能够应付这个。