使用naudio在c#应用程序中缓冲区已满

时间:2013-02-25 23:39:34

标签: c# real-time naudio

我正在尝试创建一个能够实时计算和发送语音音调(基频)的应用程序。它似乎运行良好,但在5秒后程序停止并报告缓冲区已满。

这是我的代码:

    private void button2_Click(object sender, EventArgs e)
    {
        stream = new NAudio.Wave.WaveIn();
        stream.DeviceNumber = 0;
        stream.WaveFormat = new NAudio.Wave.WaveFormat(44100, 1);
        stream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(anyue);
        stream.StartRecording();
    }

    private void anyue(object sender, NAudio.Wave.WaveInEventArgs e)
    {     
        int j = 0;
        for (int i = 0; i < 4410; i += 2)
        {
            x[j] = BitConverter.ToInt16(e.Buffer, i);
            j++;
        }

        ...
        Count pitch at segment from x[0] to x[2205] and show the result in a textbox
        ...
    }

    private void button3_Click(object sender, EventArgs e)
    {
      if (stream != null)
        {
            stream.StopRecording();
            stream.Dispose();
            stream = null;
        }            
    }

谁能告诉我它有什么问题?

0 个答案:

没有答案