IAudioClient::Initialize returns (E_InvalidArg,0x80070057,-2147024809)

1.4k views Asked by At

I use NAudio lib for creating windows service, for capturing audio from sound card,throw Wasapi. But on one of computers i get hresult = -2147024809,when i call audioClientInterface.Initialize Here is code that i use to capture.

     public partial class TestRecorder : ServiceBase
        {
            private static readonly Logger _logger = LogManager.GetLogger("ServiceLogger");

            public TestRecorder()
            {
                InitializeComponent();
            }

            protected override void OnStart(string[] args)
            {
                ThreadPool.QueueUserWorkItem(x =>
                {
                    using (var rec = new Recorder())
                    {
                        rec.Start();
                        Thread.Sleep(10000);
                        rec.Stop();
                    }

                });
            }

            protected override void OnStop()
            {
            }

            internal void TestStartupAndStop(string[] args)
            {

                this.OnStart(args);
                Console.ReadLine();
                this.OnStop();
            }
        }


Here is code of Recorder.


 public class Recorder : IDisposable
    {
        private static readonly Logger _logger = LogManager.GetLogger("ServiceLogger");

        private WasapiCapture MicroCapture { get; set; }
        private WaveFileWriter Writer { get; set; }

        public Recorder()
        {
            var deviceEnum = new MMDeviceEnumerator();
            MMDevice micro = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
            MicroCapture = new WasapiCapture(micro);
            MicroCapture.DataAvailable += OnDataAvailible;
            Writer = new WaveFileWriter(@"C:\Temp\test.wav", MicroCapture.WaveFormat);
            _logger.Trace("Recorder is initialized");
        }


        private void OnDataAvailible(object sender, WaveInEventArgs e)
        {
            if (e.BytesRecorded > 0)
            {
                Writer.Write(e.Buffer, 0, e.BytesRecorded);
            }
        }

        public void Start()
        {
            try
            {
                MicroCapture.StartRecording();
                _logger.Trace("Recorder started");

            }
            catch (Exception ex)
            {
                _logger.Fatal(ex);
            }
        }

        public void Stop()
        {
            try
            {
                MicroCapture.StopRecording();
                _logger.Trace("Recorder stopped");
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex);
            }
        }


        public void Dispose()
        {
            MicroCapture.Dispose();
            Writer.Dispose();
            _logger.Trace("Capture and writer disposed");

        }
    }

Tried to install 3 different drivers. Tried to use different formats. NAudio send next parameters
audioClientInterface.Initialize send next parameters.

   shareMode = Shared,
                    streamFlags = None, 
                    bufferDuration = 1000000, 
                    periodicity = 0, 
                    waveFormat = 32 bit PCM: 48kHz 2 channels wBitsPerSample:32 dwChannelMask:3 subFormat:00000003-0000-0010-8000-00aa00389b71 extraSize:22, 
                    audioSessionGuid = 00000000-0000-0000-0000-000000000000

In Speaker and Microphone settings i choose 48000 hz 16 bit. Please give me some hint for solving this problem on how can i debug or fix this issue. Sound card model is VIA vt1708s,mother board model is Asus P8H61-M LX3 R2.0 IAudioClient::IsFormatSupproted returns S_OK.

1

There are 1 answers

0
Faradey Inimicos On

I decided it by adding my windows service to exception of Kaspersky Antivirus application and it worked.