Browse Source
Merge pull request #661 from roadz99/eventsyncfix
Fix silent failure in WasapiCapture/WasapiOut
pull/499/merge
Mark Heath
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
6 additions and
11 deletions
-
NAudio/Wave/WaveInputs/WasapiCapture.cs
-
NAudio/Wave/WaveOutputs/WasapiOut.cs
|
|
@ -245,10 +245,9 @@ namespace NAudio.CoreAudioApi |
|
|
|
} |
|
|
|
while (captureState == CaptureState.Capturing) |
|
|
|
{ |
|
|
|
bool readBuffer = true; |
|
|
|
if (isUsingEventSync) |
|
|
|
{ |
|
|
|
readBuffer = frameEventWaitHandle.WaitOne(waitMilliseconds, false); |
|
|
|
frameEventWaitHandle.WaitOne(waitMilliseconds, false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@ -257,11 +256,8 @@ namespace NAudio.CoreAudioApi |
|
|
|
if (captureState != CaptureState.Capturing) |
|
|
|
break; |
|
|
|
|
|
|
|
// If still recording and notification is ok
|
|
|
|
if (readBuffer) |
|
|
|
{ |
|
|
|
ReadNextPacket(capture); |
|
|
|
} |
|
|
|
// If still recording
|
|
|
|
ReadNextPacket(capture); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -121,18 +121,17 @@ namespace NAudio.Wave |
|
|
|
while (playbackState != PlaybackState.Stopped) |
|
|
|
{ |
|
|
|
// If using Event Sync, Wait for notification from AudioClient or Sleep half latency
|
|
|
|
int indexHandle = 0; |
|
|
|
if (isUsingEventSync) |
|
|
|
{ |
|
|
|
indexHandle = WaitHandle.WaitAny(waitHandles, 3 * latencyMilliseconds, false); |
|
|
|
WaitHandle.WaitAny(waitHandles, 3 * latencyMilliseconds, false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Thread.Sleep(latencyMilliseconds / 2); |
|
|
|
} |
|
|
|
|
|
|
|
// If still playing and notification is ok
|
|
|
|
if (playbackState == PlaybackState.Playing && indexHandle != WaitHandle.WaitTimeout) |
|
|
|
// If still playing
|
|
|
|
if (playbackState == PlaybackState.Playing) |
|
|
|
{ |
|
|
|
// See how much buffer space is available.
|
|
|
|
int numFramesPadding; |
|
|
|