Neko :ablobcatcoffee:<p>I need to document the solution I found to a <a href="https://aus.social/tags/LinuxAudio" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>LinuxAudio</span></a> (yes, sigh) problem I was having, but I don't have a blog or anything so it'll have to fit in a toot!</p><p>🔥 Occasional Audio Crackling 🔥</p><p>Setup: Granted, I tried using <a href="https://aus.social/tags/Pipewire" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Pipewire</span></a> to do a slightly non-standard setup; a 'neko-stream-output' virtual device that is a sink for the games I play on stream, and a source for 'neko-combined-output' which goes to my speakers and BT headphones.</p><p>Symptoms: First noticed in <a href="https://aus.social/tags/DOSbox" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>DOSbox</span></a>, I heard occasional crackling that wasn't limited to game audio but seems to affect everything. The console would show `overflow run need 512, have 3332, min 960` and similar spammed during these events.</p><p>I later noticed something similar using Wine to play Ultima IX; it seems like occasionally the game would stutter, fail to fill the audio buffer, and we'd get crackly audio.</p><p>But it was intermittent, and it wasn't until I got a reproducible test case with timidity that I could figure out a fix: Using timidity on a particular file for whatever reason produced crackling almost immediately. I went through the options, and found the `-Os` option for 'output to <a href="https://aus.social/tags/ALSA" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>ALSA</span></a>. But wasn't I already using that? Comparing it with the default, it seems *explicitly* setting `-Os` got it to set the buffer size appropriately:</p><p>```<br>Requested buffer size 32768, fragment size 8192<br>ALSA pcm 'default' set buffer size 32768, period size 8192 bytes<br>```</p><p>whereas the default lacked these lines and got crackles immediately. Clues! I found that `pw-metadata -n settings 0` listed the `clock.min-quantum` as 16; that's 16 whole samples. Maybe fine for a program that can reliably supply them, but these retro games seem to hitch a bit here and there, causing problems. Running</p><p>```<br>pw-metadata -n settings 0 clock.min-quantum 512<br>```</p><p>might give me a whole 10ms of delay but completely eliminates the DOSbox crackle and mostly eliminates the Ultima IX crackle (and that game has audio issues of its own).</p><p>How do I apply that setting permanently? Uhhhh something something pipewire.conf. I dunno. I have a script. `man 5 pipewire.conf` suggests there's a `/usr/share/pipewire/pipewire.conf`, I'll take a look at it.</p><p>I sincerely hope that documenting this, even though it's a toot, enables someone in need to find it and solve their own problem.</p>