Program works fine with pulse but throws huge amount of xruns with pipewire
I have a music player application I'm writing, and it is using the miniaudio library for audio output. Under the hood, miniaudio uses the pulse callback API. In my own code, audio decode is done async and put through a lockfree SPSC queue in chunks. The consumer is simply just copying PCM data to the output buffer with no potential lockups so I'm pretty sure it's not my code that's causing xruns.
In any case, the expected behavior is for my program to play music cleanly. This is what happens in pulse with no xruns outside of exceptional circumstances. In pipewire, it outputs an intermittent buzzing noise and throws tons of xruns. Sometimes, but not every time, this issue will persist after I close my program and basically break all sound until I restart pipewire. As long as I don't open my program, other applications behave as expected.
Example pipewire output when I run my program:
...
[E][000044434.247804][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26139 time:44434838213 delay:440 max:7286
[W][000044436.265310][private.h:73 ratelimit_test()] 129 events suppressed
[E][000044436.265342][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26269 time:44436851261 delay:4944 max:7286
[W][000044438.270220][private.h:73 ratelimit_test()] 148 events suppressed
[E][000044438.270248][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26418 time:44438856271 delay:4856 max:7286
[W][000044440.271219][private.h:73 ratelimit_test()] 109 events suppressed
[E][000044440.271250][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26527 time:44440857288 delay:4852 max:7286
[W][000044442.277430][private.h:73 ratelimit_test()] 107 events suppressed
[E][000044442.277463][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26635 time:44442864294 delay:4068 max:7286
[W][000044444.288922][private.h:73 ratelimit_test()] 107 events suppressed
[E][000044444.288949][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26743 time:44444875321 delay:4547 max:7286
[W][000044446.296793][private.h:73 ratelimit_test()] 161 events suppressed
[E][000044446.296825][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:26905 time:44446887295 delay:456 max:7286
[W][000044448.298785][private.h:73 ratelimit_test()] 228 events suppressed
[E][000044448.298815][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27134 time:44448889310 delay:447 max:7286
[W][000044450.300778][private.h:73 ratelimit_test()] 228 events suppressed
[E][000044450.300807][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27363 time:44450891322 delay:440 max:7286
[W][000044452.301696][private.h:73 ratelimit_test()] 107 events suppressed
[E][000044452.301728][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27471 time:44452888373 delay:4320 max:7286
[W][000044454.313359][private.h:73 ratelimit_test()] 109 events suppressed
[E][000044454.313391][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27581 time:44454899388 delay:4980 max:7286
[W][000044456.314440][private.h:73 ratelimit_test()] 109 events suppressed
[E][000044456.314472][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27691 time:44456901405 delay:4058 max:7286
[W][000044458.331563][private.h:73 ratelimit_test()] 111 events suppressed
[E][000044458.331593][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27803 time:44458918414 delay:4184 max:7286
[W][000044460.332723][private.h:73 ratelimit_test()] 110 events suppressed
[E][000044460.332755][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:27914 time:44460919421 delay:4349 max:7286
[W][000044462.339474][private.h:73 ratelimit_test()] 123 events suppressed
[E][000044462.339509][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:28037 time:44462929814 delay:720 max:7286
[W][000044464.359690][private.h:73 ratelimit_test()] 125 events suppressed
[E][000044464.359725][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:28163 time:44464946453 delay:4308 max:7286
[W][000044466.360797][private.h:73 ratelimit_test()] 186 events suppressed
[E][000044466.360824][impl-node.c:1583 node_xrun()] (alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo-43) XRun! count:28350 time:44466951436 delay:447 max:7286
...
So far, the only thing I have tried is setting sample rate and quantum in the pipewire config but this did not seem to make any difference.
Documentation is a bit thin so I'm not sure what other debugging steps to try. I will also link this issue to the author of miniaudio to see if they have any insights.