Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Repeated Start/StopRecording does not work

$
0
0

When I start/stop recordings, while a playback is running at the same time, NAudio hangs after some time. Down below you can find a small demo that shows the effect. The test-loop is expected to loop-back recorded audio to the output device forever. But after some random record sequences no recording will take place any more and the StopRecording method call hangs.

Any idea what's wrong here? I tested with a few days old NAudio codebase, but had the same effect with the official NAudio release 1.5 too.

Norbert

 

using System;
using System.Threading;
using NAudio.Wave;

namespace NAudioRecTest
{
    class Program
    {
        static BufferedWaveProvider bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));

        static void Main(string[] args)
        {
            IWaveIn waveIn = new WaveInEvent();
            waveIn.DataAvailable += new EventHandler<WaveInEventArgs>(waveIn_DataAvailable);

            IWavePlayer waveOut = new WaveOutEvent();
            waveOut.Init(bufferedWaveProvider);
            waveOut.Play();

            while (true)
            {
                Console.Out.WriteLine("Start recording.");
                waveIn.StartRecording();

                Thread.Sleep(1000);
                
                Console.Out.WriteLine("Stop recording.");
                waveIn.StopRecording();

                Thread.Sleep(500);
            }
        }

        static void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            Console.Out.WriteLine("Data available");
            bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
        }
    }
}


Viewing all articles
Browse latest Browse all 5831

Latest Images

Trending Articles



Latest Images