naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.37k stars 1.09k forks source link

Fix a bug that WasapiCapture could not use exclusive mode #1122

Open tt3333 opened 4 months ago

tt3333 commented 4 months ago

When using exclusive mode with WasapiCapture, the InitializeCaptureDevice throws an exception. In #819 it says "you can't use it with WASAPI exclusive mode playback", but it seems that auto convert cannot be used in exclusive mode for recording as well as playback.

System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at NAudio.CoreAudioApi.AudioClient.Initialize(AudioClientShareMode shareMode, AudioClientStreamFlags streamFlags, Int64 bufferDuration, Int64 periodicity, WaveFormat waveFormat, Guid audioSessionGuid)
   at NAudio.CoreAudioApi.WasapiCapture.InitializeCaptureDevice()
   at NAudio.CoreAudioApi.WasapiCapture.StartRecording()