[The Bug] Wasn't actually a bug in Anukari

Captain's Log: Stardate 77466.9

For fuck's sake... The Bug was not in my code at all. It's something in the audio drivers for my Focusrite Scarlett. Or, possibly a bug in the way JUCE initializes the Windows audio APIs for the interface. But my money's on the Scarlett drivers.

Today the issue randomly reappeared after a few hours of not appearing at all. And I accidentally found a way to tell if it was happening within 1 second, instead of waiting 19 seconds. I just needed to generate audio immediately at application startup, and it turns out The Bug happens immediately at start for a short time before it goes into a 19 second period. This massively sped up my debugging, since I could delete code, and then restart Anukari 10 times to see if it showed the problem. And 10 * 1 second is easy, whereas 10 * 19 seconds is unbearable.

Anyway I got to the point where I had deleted literally all my application code except for a sine wave generator on the CPU. Just 5 lines of application code, and The Bug still appeared. So then I started messing with my audio settings and voila -- changing the audio device makes the issue go away. As does changing the sample rate, etc. It seems that any restart of the audio interface has a chance to fix the issue.

I was so convinced that the bug was in my GPU code. It's interesting to think about what happened to confuse me so badly. I think the main thing is the randomness. Sometimes I'd go 20-30 launches of Anukari without the issue appearing. So when I was experimenting, I think this led me to incorrect results a couple times where I thought the issue was gone, but it was really just hiding.

The other thing that got me pretty badly was that I decided early on that because the distortion was impacted by microphone gain (which is applied on the GPU), the bug must be on the GPU. But this was an incorrect assumpion: the volume of the distortion was simply mediated by the volume of whatever sound was playing.

Captain's Log: Supplemental This is all pretty damn frustrating. But at least there is a silver lining: I investigated and fixed a LOT of real bugs. I went on a crusade against all the code that could generate NaN/infinity and reasoned through the correct fixes. I greatly improved the fuzz testing setup. I fixed the egregious bug in the microphone buffer indexing. And I put in a bunch of checks that should prevent these bugs from creeping back in.

So not too much time was wasted -- mainly the main negative was just the degree of frustration I experienced due to the mystifying nature of The Bug. But I can fix that by calling it quits early today to go play some guitar. 😄


© 2024 Anukari LLC, All Rights Reserved
Contact Us|Legal