0

コード認識に関するプロジェクトに取り組んでいます。どなたかの日記を参考にしていますが、DSPの分野についてはまだほとんど把握できていません。彼女の参考文献では、最初に wav ファイルからの信号をフレーム数に分割する必要があります。私の場合、フレームごとに 2866 サンプルで、各フレームを 65 ミリ秒に分割する必要があります。

信号をフレームに分割する方法を検索しましたが、理解できるほど明確ではありません。これまでのところ、これらは 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 を分割してフレームに分割し、配列に保存する必要がありますか? それとも何か?

4

1 に答える 1

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 はこれに対処できる必要があります。

于 2012-02-13T19:08:49.513 に答える