Audacity freezing with PulseAudio

steve writes (Is it me or is it a bug? - #4 by steve):

There is one problem with using PulseAudio with Audacity, which is that on some systems, rapid starting / stopping of playback can cause Audacity to freeze. This is due to the way that Audacity connects to the sound system, which in turn is due to historical reasons. Not everyone gets this problem, but it is extremely annoying if you do.

That sounds more or less like the problem I’ve been having. I am using Audacity with PulseAudio on Fedora 28, and I get these freezes all the time, which is not only annoying but also occasionally leads to data loss. (I accidentally deleted a piece of audio, and before I hit Ctrl-Z, audacity froze, losing the undo history.)

Is this issue described anywhere in more detail? As a programmer, can I do anything to help resolve it?

It’s a tricky one to fix, which is why it has been an issue for so long.
It is logged here:

We are currently thinking that the correct fix is to change Audacity’s behaviour so that Audacity opens its audio ports once and then keeps them open until the project is closed, rather than opening and closing ports on demand.

Thanks steve. It’s interesting to me that the linked bug does not contain a mechanistic explanation of what exactly causes the issue (on the code level). The discussion moves from “most likely a bug in PortAudio’s support for libpulse” to “This particular bug could be eliminated by keeping the sound card open all the time”, without discussing the cause of the problem. Given a 4-year gap in the discussion, I’m guessing that the diagnosis was happening elsewhere.

Is there somewhere I could read about the diagnosis of the bug?

Developer discussions are mostly on the developer’s mailing list. More information here: Redirecting to:
There is an archive of the developer’s mailing list here: audacity-devel Mailing List for Audacity

There’s two ways that bug 276 could be fixed.

  1. Make connecting / disconnecting to PulseAudio more robust and handling failed connections better. This would be a good thing, and could include making use of PortAudio’s “hotplug” (HotPlug | PortAudio Project | Assembla). I think PortAudio’s hotplug feature is still considered a “work in progress”, even though it was started over 10 years ago.

  2. Keep the ports open (as suggested: Bug 276 – Linux: PULSE-AUDIO issues. Freeze repeatedly starting/stopping streams). This approach would greatly benefit working with Jack - Signal routing for recording is currently quite awkward because the ports are only present when the recording stream is started, and ports always have unique names (different names each time they are created).

Ideally we would have both.

Detailed descriptions from 4 years ago would probably not be very helpful as the Audacity code has changed a lot in that time. Also, I’m not sure how well the underlying problem is understood. It is complicated because it involves Audacity’s code, and PulseAudio’s code, and PortAudio’s code.