This project has moved and is read-only. For the latest updates, please go here.

Record from 2 microphones

May 24, 2015 at 11:32 PM
Edited May 24, 2015 at 11:33 PM
I have a laptop with native mic and a web cam with mic, i want to capture sound from these two devices. But when i'm tryin' do this i have an error:

already allocated calling waveinopen

NAudio have searched for 3 devices, and i wrote next:
    NAudio.Wave.WaveIn sourceStream = null;
    NAudio.Wave.WaveIn sourceStream2 = null;
    NAudio.Wave.WaveIn sourceStream3 = null;
    NAudio.Wave.DirectSoundOut waveOut = null;
    NAudio.Wave.DirectSoundOut waveOut2 = null;
    NAudio.Wave.DirectSoundOut waveOut3 = null;
    NAudio.Wave.WaveFileWriter waveWriter = null;
    NAudio.Wave.WaveFileWriter waveWriter2 = null;
    NAudio.Wave.WaveFileWriter waveWriter3 = null;

    private void button5_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
        {
            if (sourceStream == null)
            {
                sourceStream = new NAudio.Wave.WaveIn();
                sourceStream.DeviceNumber = i;
                sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(i).Channels);

                sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
                waveWriter = new NAudio.Wave.WaveFileWriter(String.Concat("D:/record-", i + 1, ".wav"), sourceStream.WaveFormat);

                sourceStream.StartRecording();
                continue;
            }

            if (sourceStream2 == null)
            {
                sourceStream2 = new NAudio.Wave.WaveIn();
                sourceStream2.DeviceNumber = i;
                sourceStream2.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(i).Channels);

                sourceStream2.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream2_DataAvailable);
                waveWriter2 = new NAudio.Wave.WaveFileWriter(String.Concat("D:/record-", i + 1, ".wav"), sourceStream2.WaveFormat);



                sourceStream2.StartRecording();
                continue;
            }

            if (sourceStream3 == null)
            {
                sourceStream3 = new NAudio.Wave.WaveIn();
                sourceStream3.DeviceNumber = i;
                sourceStream3.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(i).Channels);

                sourceStream3.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
                waveWriter3 = new NAudio.Wave.WaveFileWriter(String.Concat("D:/record-", i + 1, ".wav"), sourceStream3.WaveFormat);

                sourceStream3.StartRecording();
                continue;
            }
        }
    }



error occured in line: sourceStream2.StartRecording();
Jun 3, 2015 at 3:41 PM
it looks like you're trying to open the same device number for recording twice. Put some breakpoints on StartRecording, and see what DeviceNumber is,.