音频输入从多个设备捕获

时间:2013-03-14 14:25:27

标签: c# naudio

我正在使用NAudio库来捕获C#中的音频输入:

int _deviceID;
double _previewVal;
private void PreviewData()
{
    WaveIn waveIn = new WaveIn();
    waveIn.DeviceNumber = _deviceID;
    waveIn.DataAvailable += waveIn_DataAvailable;
    int sampleRate = 8000; // 8 kHz
    int channels = 1; // mono
    waveIn.WaveFormat = new WaveFormat(sampleRate, channels);
    waveIn.StartRecording();
}
void waveIn_DataAvailable(object sender, WaveInEventArgs e)
{
    for (int index = 0; index < e.BytesRecorded; index += 2)
    {
        short sample = (short)((e.Buffer[index + 1] << 8) |
                                e.Buffer[index + 0]);
        _previewVal = sample / 327.68f;
    }
}

每个音频输入设备(我的系统中为4)同时调用函数PreviewData。 当我只调用一个设备的方法时,它似乎正在工作,但如果我再次调用它,我会得到异常“AlreadyAllocated calling waveInOpen”。 有人知道如何解决这个问题吗?

0 个答案:

没有答案
相关问题