Fixing an audio bug that's haunted me for 2 weeks

If you rather look at the code instead, you can find it here.

Could be four weeks, really. I'm not sure at this point, but I'm glad to have fixed the clicking sound I used to hear between buffers. It's been about a month since I started playing around with audio. It started off with using ALSA, and then when I saw it was calling PulseAudio internally, I decided to skip the middleman and go straight to the source. I managed to get the audio working quite fast. There is a simple API for simpletons like myself. I did dabble with the "complex" async API, but all I managed to do was keep an instance perpetually open, and I no longer have access to it. So I switched back to the Simple API and got it to work. The only reason for switching to the Async API was because it was async. The Simple API blocks every time it plays a buffer, which is no good because I can't have the thread block for a second every time I need audio to play. So I opted to use thread pools in Zig, which were super simple, thanks to the Zig standard library.

The problem that has been plaguing me for the last couple of weeks was that there was a clicking sound every time the buffer switched. The problem was not something I had guessed at all. I tried smoothing out the audio curve and added larger pre-buffers, but no luck. If my debugger was working, which hasn't been working since I upgraded Zig to use 0.15.1. The problem would have been apparent instantly if it had been. Eventually, with the help of Claude, I was able to figure out that the clicking was caused by something very simple. You see, I was using a simple sine wave to test the audio. In between buffers, I wasn't keeping track of the wave position. So on every new buffer, the wave would start from zero. The fix was quite simple: save the wave position in the game state and then always use this as the starting point. At least it seems trivial now. I do miss the debugger.