PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.43k stars 296 forks source link

Windows DirectSound sometimes stalls after a few buffers (?regression 2016 -> 2018) #525

Open touil opened 3 years ago

touil commented 3 years ago

The streaming with DirectSound just stalls after a few buffers. MME, ASIO, WASAPI do not exhibit this behavior. WDMKS is consuming the buffers, but there doesn't seem to be any playback.

philburk commented 3 years ago

@touil - Thanks for the report. We will try to reproduce the error but need more information.

What version of Windows are you using?

What model of PC is it? Dell? Lenovo?

What audio device are you using? Built-in? USB device? Are all devices failing?

What app are you using? Your own or a public app? Does bin/paex_sine work?

dechamps commented 3 years ago

The streaming with DirectSound just stalls after a few buffers.

What buffer sizes (and suggested latency) are you using? Is this capture, playback, or both?

I have observed some time ago that DirectSound does indeed stall after a few initial callbacks if using small-ish buffers (<60 ms) in the capture direction. As far as I can tell this is an issue in DirectSound itself and there is not much that PortAudio can do about it.

touil commented 3 years ago

This happens with the default master build on Windows 10.0.19041.867 which is most recent patch level as of today. This is an ASUS N550JV laptop. The app in question is SDR# which can be obtained from https://airspy.com/download and it's using 50ms buffers. The old 2016 release of portaudio is not affected and just works.

philburk commented 3 years ago

@touil - Thanks for the update.

We need to know if this is a recent regression. Can you please test with the code that we left on Assembla? The dsound folder on Assembla was last changed on 2018-10-02.

cd {some_temp_folder}
git clone  https://git.assembla.com/portaudio.git

I looked on GitHub. The only changes in hostapi/dsound since we migrated from Assembla were changes for UNICODE char handling, spelling changes, white space changes.

https://github.com/PortAudio/portaudio/commits/master/src/hostapi/dsound
touil commented 3 years ago

I have just checked and the dsound problem is there as well. I used VC++ 2019 v16.9.1.

philburk commented 3 years ago

That is good to know. So the DSound problem has probably been in there since 2018.

Do you think WDMKS non-playback is a different bug. If so then it should have a different Issue #. It may be a more recent regression.

RossBencina commented 3 years ago

I have tested PA/DirectSound here with 1024, 2048, 4096 sample buffers (total buffer size, latency: 23.2, 46.4, 92.8) and it is working for me using the "Primary Sound Driver" device on Windows 10 1909 build 18363.1216). With 512 sample buffers the sound breaks up, but that was the case also with older versions of DirectSound.

There have been 6 commits to the DirectSound code since 2016: https://github.com/PortAudio/portaudio/commits/master/src/hostapi/dsound/pa_win_ds.c Most of them are whitespace and typo fixes. There was only one real change:

https://github.com/PortAudio/portaudio/commit/ea11061b20f637f8f707a4a225d37ff58ab54dc0#diff-c07d6f6669b6584c597b04f52c5863053c5bbb7ac1846bba30d0b5b811e60b23

Which seems unlikely to be an issue (sizeof(int) == sizeof(long) on Windows).

@touil Could you please confirm that ea11061b20f637f8f707a4a225d37ff58ab54dc0 has the problem, but b3216e814b667915418098f124ea9a841304fc7b does not have the problem? (you can check out a specific revision with git checkout put-the-hash-code-here

RossBencina commented 3 years ago

I've split the WDMKS issue out into #533. Please continue the WDMKS conversation there.

philburk commented 3 years ago

We are removing the DirectSound bug from the Milestone 19.7 so it will not block the release.

We are punting the DirectSound part of this bug because we have examined the commits since 2016 and found no significant changes in the src/common code or the hostapi/dsound code. We cannot reproduce the stalls in DirectSound. And this bug has become inactive.

RossBencina commented 2 years ago

It remains unclear whether the reported issue is playback-only or full-duplex. It would be helpful to know that. Checking my notes I see that I only tested playback when reporting no problem here.

RossBencina commented 2 years ago

I'm demoting this to P4 because

RossBencina commented 4 months ago

After reviewing the comments again, it still seems like this might be a PortAudio regression since it was working in 2016 and then didn't work in 2018. Phil suggests it might be a problem outside the DirectSound code. At this stage, we don't have enough information to fix this. The next step would be to create a minimal reproducing test case and perform a bisection back to 2016 to find the offending commit.

Removing this from any milestone.

We would welcome feedback from anyone who is observing this bug on their system.