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

Forward 1 input (waveIN) to 2 outputs (waveout)

Nov 20, 2013 at 6:21 PM
Edited Nov 20, 2013 at 6:22 PM
I am trying to get one input to forward out of 2 outputs as real time as i can get it.

I have it working fine with one in and one out but then i create a 2nd wavein and waveout and i get a buffer full error.
    private void StartBtnOutput2_Click(object sender, EventArgs e)
        {
            if (waveIn2 != null)
                return;



            // create wave input from mic
            waveIn2 = new WaveIn(this.Handle);
            waveIn2.DeviceNumber = comboBoxInput.SelectedIndex;
            waveIn2.BufferMilliseconds = 25;
            waveIn2.RecordingStopped += waveIn_RecordingStopped2;
            waveIn2.DataAvailable += waveIn_DataAvailable2;

            waveIn2.WaveFormat = new NAudio.Wave.WaveFormat(44100, 16, 2);


            // create wave provider
            waveProvider2 = new BufferedWaveProvider(waveIn2.WaveFormat);

            // create wave output to speakers
            waveOut2 = new WaveOut();
            waveOut2.DeviceNumber = comboBoxOutput2.SelectedIndex;
            waveOut2.DesiredLatency = 60;
            waveOut2.Init(waveProvider2);
            waveOut2.PlaybackStopped += wavePlayer_PlaybackStopped2;

            // start recording and playback
            waveIn2.StartRecording();

            waveOut2.Play();
        }

        void waveIn_DataAvailable2(object sender, WaveInEventArgs e)
        {
            // add received data to waveProvider buffer
            if (waveProvider2 != null)
                waveProvider2.AddSamples(e.Buffer, 0, e.BytesRecorded);
        }



        void waveIn_RecordingStopped2(object sender, StoppedEventArgs e)
        {
            // stop playback
            if (waveOut2 != null)
                waveOut2.Stop();

            // dispose of wave input
            if (waveIn2 != null)
            {
                waveIn2.Dispose();
                waveIn2 = null;
            }

            // drop wave provider
            waveProvider2 = null;
        }

        void wavePlayer_PlaybackStopped2(object sender, StoppedEventArgs e)
        {
            // stop recording
            if (waveIn2 != null)
                waveIn2.StopRecording();

            // dispose of wave output
            if (waveOut2 != null)
            {
                waveOut2.Dispose();
                waveOut2 = null;
            }
        }
Nov 21, 2013 at 4:36 PM
You need to have one instance of WaveIn, and two BufferedWaveProviders. Start two instances of WaveOut playing from each of the BufferedWaveProviders respectively. When you get a data available event, copy the audio received into both BufferedWaveProviders.
Dec 24, 2013 at 4:59 PM
please can any one tell me how can i take sample of the wave file if that is mono will take mono or stereo will take it as it without any convert plaseeeeeeeeee