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

100% CPU usage on default microphone input switching. #813

Open rwchateau opened 1 year ago

rwchateau commented 1 year ago

(Please use the mailing list for support requests and general discussion. This is only for actual bugs.)

Describe the bug We noticed that when we switched the default input via the ubuntu settings our application would spike to 100% cpu usage and stay there.

To Reproduce Our applicatition opens on startup a stream both with the Default Input and Output device. When switching the default microphone of the system based on Ubuntu 22.04 the application would spike to 100% CPU usages and stay there. We needed to restart the application to fix the problem. It also happend when disconnecting a bluetooth headset, that was the only input device, therefor having no input device, then connecting it again and selecting that as the default input again.

Expected behavior The same CPU usage after switching the default input device as before switching it.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

RossBencina commented 1 year ago

Are you able to localise the problem to ALSA or PortAudio using a profiler? or just drop in with a debugger and see where it is stuck.

rwchateau commented 1 year ago

Hi RossBencina,

A couple of days after making this issue we replaced pulseaudio with pipewire/wireplumber on the affected systems and were unable to reproduce the problem. Time was limited and because of some other problems we kept the pipewire/wireplumber setup.

I will try to make some time at the end of this or beginning of next week to do some profiling.

rouseabout commented 9 months ago

I experience this problem too when using PortAudio ALSA to connect to a duplex portaudio server.

Steps to reproduce:

  1. Open duplex stream using ASLA hostapi on 'default' device (pulseaudio backend).
  2. Enable a new input device in pulseaudio, either using pavucontrol, or plugging in USB DAC.
  3. Watch CPU utilisation of the portaudio process climb to 100%.
  4. The portaudio interrupt is still serviced, but there is noticible delay, depending on what other device was enabled/plugged in.

Tested on Debian.

Debugging:

I have tried to instrument libportaudio to understand the cause of the high CPU load. It appears there is a busy loop that goes something like this:

rouseabout commented 9 months ago

Switching to pipewire and the issue goes away.