Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WDM-KS fails to open WaveRT devices with suggestedLatency=0 #761

Closed
dechamps opened this issue Jan 21, 2023 · 4 comments · Fixed by #762
Closed

WDM-KS fails to open WaveRT devices with suggestedLatency=0 #761

dechamps opened this issue Jan 21, 2023 · 4 comments · Fixed by #762
Labels
P2 Priority: High src-wdmks MS WDM/KS Host API /src/hostapi/wdmks

Comments

@dechamps
Copy link
Contributor

dechamps commented Jan 21, 2023

Describe the bug
If the following conditions are true:

  • PaStreamParameters::suggestedLatency is set to zero;
  • The device being opened is backed by the WDM-KS Host API;
  • The Windows driver for the device being opened uses WaveRT (most modern drivers do);

Then Pa_OpenStream() will fail.

To Reproduce

  1. Change examples/paex_sine.c:
    • Set suggestedLatency to zero.
    • Set device to the index of a WDM-KS device that happens to use WaveRT.
      • Virtual Audio Cable can be used to emulate a WaveRT device, as well as WavePci and WaveCyclic for comparison.
  2. Run the example.

Expected behavior
The example runs and plays sound for 5 seconds.

Actual behavior
Pa_OpenStream() fails with the following debug output:

 0.072: OpenStream:sampleRate = 44100.000000
 0.072: OpenStream:framesPerBuffer = 64
 0.072: Pin create result = 0x00000000
 0.072: Render pin frames: 0
 0.072: Output frames chosen:0
 0.072: Failed to get buffer with notification
 0.073: Failed to get buffer without notification
 0.073: Buffer size on 128 byte boundary, still fails :(
 0.073: Failed to get output buffer (with notification)
TerminateHostApis in
TerminateHostApis out
An error occurred while using the portaudio stream
Error number: -9999
Error message: Unanticipated host error

Desktop:

  • OS Version: Windows 11 21H2 22000.1455, but this doesn't seem to matter (it has been observed on Windows 10 too)
  • PortAudio version: latest master (bbe2b5a), and going back to at least 80ef9ac
  • Host API: WDM-KS

Additional context

@dechamps
Copy link
Contributor Author

Digging further, the PortAudio WDM-KS code is issuing a KSRTAUDIO_BUFFER_PROPERTY request with a RequestedBufferSize of zero in this case.

Now in theory this is supposed to work, according to the Microsoft docs linked above and the KSPROPERTY_RTAUDIO_BUFFER docs:

The value that the client writes into the RequestedBufferSize member is not binding on the driver. However, the driver must specify a buffer size that is as close as possible to the requested size, taking into account the buffer size constraints on the driver itself. The driver allocates a buffer of a different size if the hardware cannot handle the requested size or the system is low on memory.

the actual size of the buffer is the requested size rounded (up or down) to the nearest sample or other hardware-constrained boundary. The actual size must be at least the requested size

Theoretically, according to the above, the driver should accept zero and then return the smallest buffer size it supports. It could be that there is an undocumented constraint that this parameter cannot be zero.

dechamps added a commit to dechamps/portaudio that referenced this issue Jan 21, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WinRT
devices if suggestedLatency is zero.

Fixes PortAudio#761
@RossBencina
Copy link
Collaborator

Something is fishy here.

You have written:

 0.072: OpenStream:framesPerBuffer = 64

And later,

PortAudio WDM-KS code is issuing a KSRTAUDIO_BUFFER_PROPERTY request with a RequestedBufferSize of zero in this case.

There's no way the code should be requesting zero buffer size if framesPerBuffer is 64. The only scenario where RequestedBufferSize could reasonably be zero is if suggestedLatency is 0 and framesPerBuffer is paFramesPerBufferUnspecified (or any other constant that indicates unspecified buffer size).

A second comment: if this is a workaround for KSRTAUDIO_BUFFER_PROPERTY/RequestedBufferSize behavior, then the clamp to 1 if 0 should be performed just prior to the KSRTAUDIO_BUFFER_PROPERTY command.

@RossBencina
Copy link
Collaborator

I've created a separate issue regarding taking framesPerBuffer into account. Let's keep that as a separate issue: #764

@philburk
Copy link
Collaborator

Thanks for finding this issue.

Theoretically, according to the above, the driver should accept zero

I'm not sure that follows from the doc. A buffer size of zero may just be an unreasonable or illegal value.
The is definitely a bug. But I don't know if the bug is in PortAudio or WDMKS.
But in any event, we should avoid passing zero to WDMKS.

@RossBencina RossBencina added src-wdmks MS WDM/KS Host API /src/hostapi/wdmks P2 Priority: High labels Jan 31, 2023
dechamps added a commit to dechamps/portaudio that referenced this issue Feb 2, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WinRT
devices if suggestedLatency is zero.

Fixes PortAudio#761
dechamps added a commit to dechamps/portaudio that referenced this issue Feb 18, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WinRT
devices if suggestedLatency is zero.

Fixes PortAudio#761
dechamps added a commit to dechamps/portaudio that referenced this issue Feb 18, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WinRT
devices if suggestedLatency is zero.

Fixes PortAudio#761
@dechamps dechamps changed the title WDM-KS fails to open WinRT devices with suggestedLatency=0 WDM-KS fails to open WaveRT devices with suggestedLatency=0 Feb 18, 2023
dechamps added a commit to dechamps/portaudio that referenced this issue Feb 18, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WaveRT
devices if suggestedLatency is zero.

Fixes PortAudio#761
dechamps added a commit to dechamps/portaudio that referenced this issue Feb 21, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WaveRT
devices if suggestedLatency is zero.

Fixes PortAudio#761
RossBencina pushed a commit that referenced this issue Mar 13, 2023
This fixes an issue where Pa_OpenStream() would fail on WDM-KS WaveRT
devices if suggestedLatency is zero.

Fixes #761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Priority: High src-wdmks MS WDM/KS Host API /src/hostapi/wdmks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants